Not getting 100% of my email body being composed

Hi guys,

So i’m trying to make it so that when input is saved to my database it can be picked up by my emailer to compose the body, now at the moment I have it working until it writes mydata.dateMonth ect even the “/” isn’t appearing but everything before this is appearing and i’m almost 99% sure its not my database as i’m using it else were in my app with the same variables and it works perfectly. It’s just the emailer not working with it anyone know why this is?

[/lua]

local function OnbtnSend( event )

– compose an HTML email with two attachments

local options =

{

  to = { “MobileDevelopmentTesting@gmail.com” },

  subject = “Incident Report”,

  isBodyHtml = true,

  body = “<html><body><p>Incident Date:</p></body></html>” …myData.dateDay," / " …myData.dateMonth, " / " …myData.dateYear

}

local result = native.showPopup(“mail”, options)

if not result then

print( “Mail Not supported/setup on this device” )

native.showAlert( “Warning!”,

“ERROR: Mail not supported/setup on this device. Contact Support”, { “OK” }

);

end

– NOTE: options table (and all child properties) are optional

end

[/lua]

Thanks again,

Matt.

Hi Matt,

It looks like you’re not passing a valid STRING to the “body” parameter. Instead, you have a string, then you concantenate (join) that to “myData.dateDay”. But then you use a comma which separates the next part into a new string, and you do it again a second time. I’m surprised that you’re not actually getting an error in this code… well, maybe you actually are.

Best regards,

Brent

Thanks for clearing this up, how do you suggest I combat this?

Thank Matt.

Hi Matt,

Well, you need to pass a string value, it’s basically that simple. :slight_smile:

Brent

Hi Brent,

This may be a silly question but how would that look as I don’t think I can get my head around it? 

Thanks,

Matt.

Let’s look at your code… First, it’s using HTML (HyperText Markup Language).  This is an XML based structure that clearly defines tags that demark various parts of the content.  Here is your markup:

\<html\> \<body\> \<p\>Incident Date:\</p\> \</body\> \</html\> then you have this code which is invalid: myData.dateDay," / " ..myData.dateMonth, " / " ..myData.dateYear

So the net effect is, the only valid HTML is between the <html> and </html> tags. Anything after that’s not going to be included. 

Then you have an error: myData.dateDay," / "  probably should be myData.dateDay … " / "  The comma there is invalid.  Of course you want to get these values as part of your valid HTML, so what you likely really want is:

body = "\<html\>\<body\>\<p\>Incident Date: ".. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. "\</p\>\</body\>\</html\>"

You might also want to consider using Lua’s other “quote marks”:  [[and]].  These support multi-line. Your HTML may need to use “”'s as part of the HTML, so I would take this one other step:

body = [[\<html\> \<body\> \<p\>Incident Date:]] .. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. [[\</p\> \</body\> \</html\>]]

I presume you’re going to want to put more information in the email other than the date.

Rob

That’s cleared so much up for me thanks Rob.

Matt.

Hi again,

I can’t quite work out how to make the multi line work. This is what i’m trying could you take a look and see where i’m going wrong?

[lua]

local function OnbtnSend( event )

– compose an HTML email with two attachments

local options =

{

  to = { “MobileDevelopmentTesting@gmail.com” },

  subject = “Incident Report”,

  isBodyHtml = true,

body = [[<html>

   <body>

       <p>Incident Date: ]] … myData.dateDay … " / " … myData.dateMonth … " / " … myData.dateYear … [[</p>]]

       [[<p>Line 2]] [[</p>

   </body>

</html>]] }

local result = native.showPopup(“mail”, options)

if not result then

print( “Mail Not supported/setup on this device” )

native.showAlert( “Warning!”,

“ERROR: Mail not supported/setup on this device. Contact Support”, { “OK” }

);

end

– NOTE: options table (and all child properties) are optional

end

[/lua]

Thanks again.

Matt.

body = [[\<html\> &nbsp; &nbsp;\<body\> &nbsp; &nbsp; &nbsp; &nbsp;\<p\>Incident Date:]] .. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. [[\</p\> &nbsp; &nbsp; &nbsp; &nbsp;\<p\>Line 2 \</p\> &nbsp; &nbsp;\</body\> \</html\>]] }

I don’t know how useful this will be, but [[starts a multi-line string and]] closes it.  In you case, Line 2 is just fixed text. You’re not using a variable for it, so the last place where data is inserted you close that line with [[</p>  after that put your next HTML tags on the next line.  But you probably want more than “Line 2” to print, you want to do more variables, so something like this will be a better example:

body = [[\<html\> &nbsp; &nbsp;\<body\> &nbsp; &nbsp; &nbsp; &nbsp;\<p\>Incident Date:]] .. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. [[\</p\> &nbsp; &nbsp; &nbsp; &nbsp;\<p\>Incident Description:]] .. myData.description .. [[\</p\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<p\>Name:]] .. myData.name .. [[\</p\> &nbsp; &nbsp;\</body\> \</html\>]] }

OF course I’m making things up there, but hopefully it will provide better syntax for you to work with.

Rob

Thanks for that extension here Rob this has really helped.

Thanks again,

Matt.

It seems as if it is in fact working now but the only issue is that it is making three empty lines between each paragraph is there a way to make it only create one empty line between each line rather than three?

Matt.

What device are you testing on?  Different email clients might have different spacings for paragraphs.  3 lines seems weird though, usually it’s one empty line between.  Any way, you can attack it with HTML by starting the whole message with a <p> and close the whole thing with another </p> and then use <br /> tags to put each line of the paragraph on a newline and avoid whatever default spacing your mail client’s app is applying to the paragraph tags.

The other option is to insert a little CSS to change how the <p> tag behaves.  Something like this:

\<html\> &nbsp;&nbsp;&nbsp; \<head\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<style\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p { margin-bottom: 5px; padding-bottom: 0px; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \</style\> &nbsp;&nbsp;&nbsp; \</head\> &nbsp;&nbsp;&nbsp; \<body\> &nbsp;&nbsp;&nbsp; ....

Rob

Hi Rob,

I tried adding the css style to my function and it just made it appear as normal text in the email. Am I doing this correctly?

[lua]

local function OnbtnSend( event )

– compose an HTML email with two attachments

local options =

{

  to = { “MobileDevelopmentTesting@gmail.com” },

  subject = “Incident Report”,

  isBodyHtml = true,

body = [[<html>

<head>

        <style>

              p { margin-bottom: 5px; padding-bottom: 0px; }

          </style>

          </head>

         

  <body>

       <p>Incident Date: ]] … myData.dateDay … " / " … myData.dateMonth … " / " … myData.dateYear … [[</p>

       <p>Incident Time: ]] … myData.timeHour … " : " … myData.timeMinute … [[</p>

       <p>Did the Incident Cause Harm?: ]] … myData.IRb1 … [[</p>

       <p>Who Was Affected By or At Risk By the Incident?: ]] … myData.IRb2 … [[</p>

       <p>Where Did the Incident Take Place?: ]] … myData.incidentLocation … [[</p>

       <p>Severity of Harm or Damage Caused: ]] … myData.IRb3 … [[</p>

       <p>Indicated Part of the Body Affected: ]] … myData.injuryOccurred … [[</p>

       <p>What Caused the Incident?: ]] … myData.IRb4 … [[</p>

       <p>If Caused By Height, Distance Of Fall?: ]] … myData.fallHeight … [[</p>

       <p>If Other, Description of Selection?: ]] … myData.textOther … [[</p>

       <p>Brief Description: ]] … myData.breifDes … [[</p>

       <p>Medical Intervention: ]] … myData.IRb5 … [[</p>

       <p>What Was the Outcome?: ]] … myData.IRb6 … [[</p>

       <p>Immediate Action Taken: ]] … myData.actionTaken … [[</p>

       <p>Person(s) Affected By the Incident (Name): ]] … myData.nameAffected … [[</p>

       <p>Person(s) Affected By the Incident (Email): ]] … myData.affectedEmail … [[</p>

       <p>Person(s) Affected By the Incident (Phone): ]] … myData.affectedPhone … [[</p>

       <p>Person(s) Affected By the Incident (Student Info): ]] … myData.studentSchool … [[</p>

       <p>Person(s) Affected By the Incident (Staff Info): ]] … myData.staffDepartment … [[</p>

       <p>Person(s) Affected By the Incident (Staff Line Mgr): ]] … myData.lineManagersName … [[</p>

       <p>Witnesses to the Incident:(Name): ]] … myData.witnessName … [[</p>

       <p>Witnesses to the Incident:(Email): ]] … myData.witnessEmail … [[</p>

       <p>Witnesses to the Incident:(Phone): ]] … myData.witnessPhone … [[</p>

       <p>Witnesses to the Incident:(Student Info): ]] … myData.witnessStudentSchool … [[</p>

       <p>Witnesses to the Incident:(Staff Info): ]] … myData.witnessStaffDepartment … [[</p>

       <p>Person Reporting the Incident:(Name): ]] … myData.reportingName … [[</p>

       <p>Person Reporting the Incident:(Email): ]] … myData.reportingEmail … [[</p>

       <p>Person Reporting the Incident:(Phone): ]] … myData.reportingPhone … [[</p>

       <p>Person Reporting the Incident:(Student Info): ]] … myData.reportingStudentSchool … [[</p>

       <p>Person Reporting the Incident:(Staff Info): ]] … myData.reportingStaffDepartment … [[</p>

   </body>

</html>]] }

local result = native.showPopup(“mail”, options)

if not result then

print( “Mail Not supported/setup on this device” )

native.showAlert( “Warning!”,

“ERROR: Mail not supported/setup on this device. Contact Support”, { “OK” }

);

end

– NOTE: options table (and all child properties) are optional

end

[/lua]

Thanks again,

Matt.

Hi Matt,

It looks like you’re not passing a valid STRING to the “body” parameter. Instead, you have a string, then you concantenate (join) that to “myData.dateDay”. But then you use a comma which separates the next part into a new string, and you do it again a second time. I’m surprised that you’re not actually getting an error in this code… well, maybe you actually are.

Best regards,

Brent

Thanks for clearing this up, how do you suggest I combat this?

Thank Matt.

Hi Matt,

Well, you need to pass a string value, it’s basically that simple. :slight_smile:

Brent

Hi Brent,

This may be a silly question but how would that look as I don’t think I can get my head around it? 

Thanks,

Matt.

Let’s look at your code… First, it’s using HTML (HyperText Markup Language).  This is an XML based structure that clearly defines tags that demark various parts of the content.  Here is your markup:

\<html\> \<body\> \<p\>Incident Date:\</p\> \</body\> \</html\> then you have this code which is invalid: myData.dateDay," / " ..myData.dateMonth, " / " ..myData.dateYear

So the net effect is, the only valid HTML is between the <html> and </html> tags. Anything after that’s not going to be included. 

Then you have an error: myData.dateDay," / "  probably should be myData.dateDay … " / "  The comma there is invalid.  Of course you want to get these values as part of your valid HTML, so what you likely really want is:

body = "\<html\>\<body\>\<p\>Incident Date: ".. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. "\</p\>\</body\>\</html\>"

You might also want to consider using Lua’s other “quote marks”:  [[and]].  These support multi-line. Your HTML may need to use “”'s as part of the HTML, so I would take this one other step:

body = [[\<html\> \<body\> \<p\>Incident Date:]] .. myData.dateDay .. " / " .. myData.dateMonth .. " / " .. myData.dateYear .. [[\</p\> \</body\> \</html\>]]

I presume you’re going to want to put more information in the email other than the date.

Rob

That’s cleared so much up for me thanks Rob.

Matt.

Hi again,

I can’t quite work out how to make the multi line work. This is what i’m trying could you take a look and see where i’m going wrong?

[lua]

local function OnbtnSend( event )

– compose an HTML email with two attachments

local options =

{

  to = { “MobileDevelopmentTesting@gmail.com” },

  subject = “Incident Report”,

  isBodyHtml = true,

body = [[<html>

   <body>

       <p>Incident Date: ]] … myData.dateDay … " / " … myData.dateMonth … " / " … myData.dateYear … [[</p>]]

       [[<p>Line 2]] [[</p>

   </body>

</html>]] }

local result = native.showPopup(“mail”, options)

if not result then

print( “Mail Not supported/setup on this device” )

native.showAlert( “Warning!”,

“ERROR: Mail not supported/setup on this device. Contact Support”, { “OK” }

);

end

– NOTE: options table (and all child properties) are optional

end

[/lua]

Thanks again.

Matt.