Sending An EMail From Corona

Hi All,
 
 
 
Can anyone please let me know if it is better to use system.openURL( "mailto: … ) rather than native.showPopup( “mail”, options ).
 
Is there any difference between the two and if so what are the pro’s and con’s of both?
 
 
Secondly, I have an issue with inserting line breaks in the body of the email - the standard \n does not work.
 
 e.g. 
 
[lua]
system.openURL( “mailto:test@hotmail.com?subject=Test Subject&body=Line1\n\nLine2\n\nLine 3” )
[/lua]
 
or 
 
[lua]
local options = 

{

to = “test@hotmail.com”,
subject = “Test Subject”,
body = “Line1\n\nLine2\n\nLine3”,

}

native.showPopup( “mail”, options )
[/lua]
 
Both of the above bring up the Compose EMail dialog but neither give me the line breaks I require in the body - all I get in the body is “Line1Line2Line3”.
 
Any help would be greatly received.
 
 
Thanks

Hi,

Quick bump.

I can see that the post has had 25 views but no replies - can nobody help out there?

Thanks

You might want to try Lua’s natural multi-line string quotes:

[[and]]  such as:

[[This is one line of text.

This is another line of text.

This is the third line of text.]]

They work just like “” or ‘’ except that [[]] allows line breaks in between.

Rob

Hi Rob,

I tried your suggestion of using [[]] but unfortunately that did not work.

Surely, you are allowed to prepopulate the email body with text which has line feeds in it or is this a bug that needs reprting?

Also, is there any benefit is using native.showPopup over system.openUrl( “mailto:…” ).

Thanks

system.openUrl() will background your app which requires the user to bring your app back to the foreground.  native.showPopup() will leave your app in the foreground when done.

Rob

Hi Rob,

Thanks for the clarification of the difference between the 2.

So could you please confirm that native.showPopup() does support a body having multiple line and if that is in fact the case then how is it implemented because neither the \n or the [[]] methods work.

Should I report this officially as a bug?

I am running on Windows 7 with Corona 2015.2625.

Thanks

I ran a quick test.  It’s working as expected.  E-Mail works in two ways:  HTML mode and Plain Text mode.  If you set isBodyHTML to false, you get plain mode.  The [[]] quotes put each line of text onto a separate line and expected.  In HTML mode, you have to use HTML tags for managing your text.  HTML ignores white space.  Multiple spaces, newlines are all reduced to a single space unless you’ve put in a non-breaking space ( ).  If you want text on multiple lines, you have to use <br /> tags or better wrap each paragraph in a <p> and </p> tags. 

Rob

Hi Rob,

Thanks for your reply but I don’t think I can agree with you that everything is working as it should be.

I have created a main.lua with just 30 lines of code in it - I would appreciate if you or anyone else reading this post to cut and paste this code and see if the multiline email works as it should.

I have attached 2 screenshots. The first screenshot is what I am expecting to see from an Android device and the second is what I actually see.

main.lua

local sendTo = "test@hotmail.com" local emailSubject = "A Test Subject" local fromName = "Anil" local fromEMail = "Anil@HotMail.Com" local paragraph = [[Line 1 of Test Line 2 of Test Line 3 of Test]] local blankLine = [[]] local bodyString = "Name: " .. fromName .. blankLine .. blankLine .. "EMail: " .. fromEMail .. blankLine .. paragraph print( bodyString ) local options = { to = sendTo, subject = emailSubject, body = bodyString, } if not native.showPopup( "mail", options ) then system.openURL( "mailto:" .. sendTo .. "?subject=showPopup Failed - Using openURL - " .. emailSubject .. "&body=" .. bodyString ) end&nbsp;

Thanks for your continued support.

Anil

PS For some reason, the showPopup doesn’t work on my Kindle Fire but the system.openURL does.

Try adding isBodyHTML = false to your options table.

Hi Rob,

I added the isBodyHTML = false (even though this is the default) and still does not work on the device or the Windows simulator.

Could you please send me your snippet of code that you have tested and works for you and I will test it on my setup here and see if it works for me.

Sorry to be a continued pain.

Thanks

Hi Rob,

Any chance on you posting your working test code as mine definately does not produce the correct results even when you use [[]] and the isBodyHTML = false.

Thanks

I’m using the ComposeEmailSMS sample app in CoronaSDK/SampleCode/Networking

-- onRelease listener for 'sendEmail' button local function onSendEmail( event ) -- compose an HTML email with two attachments local options = { to = { "john.doe@somewhere.com", "jane.doe@somewhere.com" }, cc = { "john.smith@somewhere.com", "jane.smith@somewhere.com" }, subject = "My High Score", isBodyHtml = false, --true, --body = [[\<html\>\<body\>I scored over \<b\>9000\</b\>!!! Can you do better?\</body\>\</html\> body = [[this is more text this is even more text this is a lot more text]], attachment = { { baseDir=system.ResourceDirectory, filename="email.png", type="image" }, { baseDir=system.ResourceDirectory, filename="coronalogo.png", type="image" }, }, } local result = native.showPopup("mail", options) if not result then print( "Mail Not supported/setup on this device" ) native.showAlert( "Alert!", "Mail not supported/setup on this device.", { "OK" } ); end -- NOTE: options table (and all child properties) are optional end

I think I see the problem, its .isBodyHtml not .isBodyHTML it appears!

Rob

Hi Rob,

I have cut and paste your code into a new blank project and as you can see from the attached screenshot from my Kindle Fire, the issue still persists i.e there are no line breaks in the body text.

I am using Window 7 with Corona 2015.2625 and the device is a Kindle Fire and Hotmail is my email client.

Should I raise this as a bug?

Thanks for the help to date.

Anil

Do you have objections to trying HTML?

<p>This is the first paragraph/line</p>

<p>This is the second paragraph/line</p>

<p>This is the third paragraph/line</p>

Rob

Hi Rob,

I tried using html with paragraphs as per your code (I obviously set isBodyHtml = true) to enable the html but unfortunately the error still persists on the Kindle Fire device - I have attached the latest screenshot. I even tried using GMail rather than Hotmail but got the same issue.

I can confirm that the code runs as expected on an HTC Desire Android phone so it looks as though there is definately an issue with showPopup( “mail” ) on a Kindle Fire HD 7" tablet. 

My app will definately be targeting the Amazon store so this is a major cause for concern as I will be prepopulating the email body with mutliple lines of text.

So how would you like to proceed from here?

Thanks

Anil

Go ahead and file a bug.  Zip up a project that demonstrates the issue and use the Report a Bug link at the top of the page.    Please post the bug number back here when you get it.

In the mean time, I’ll try the code on my Kindle Fire and see if I can work out something.

Rob

I just ran this on my Kindle Fire (1st Ed).  Here is my screen shot…  This is the no HTML version that I first showed you above.  Things are on separate lines as expected.

I wonder if it’s an issue with the email client on that version of the Kindle Fire?

Rob

Hi Rob,

Sorry I haven’t got back to you but been out of town and have just got back.

I didn’t load a particular email client on the Kindle Fire - it is the one that came out of the box.

I will see if I can load a different email client on the Kindle Fire and test that but even if that does work, it really doesn’t help as I need it to work for all Kindle Fire’s out there.

Anyway, I will try to load an alternative email client and get back to you but will also zip up a sample project and get ready to submit a bug report in the next day or so.

Many thanks for your help to date - I will update you tomorrow.

Hi,

Quick bump.

I can see that the post has had 25 views but no replies - can nobody help out there?

Thanks

You might want to try Lua’s natural multi-line string quotes:

[[and]]  such as:

[[This is one line of text.

This is another line of text.

This is the third line of text.]]

They work just like “” or ‘’ except that [[]] allows line breaks in between.

Rob