Home AMX User Forum NetLinx Studio

Generate HTML Formatted e-mail?

Hi. Just wondering if anyone has tried (with success) to create an HTML formatted e-mail from an AMX Netlinx Master. I have some log files I would like to send on a daily basis, and they would look much nicer if I could format the output with HTML.

Thanks!


Mark

Comments

  • GregGGregG Posts: 251
    Just create the email body of the log output with a mime section like this:
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Type: text/html; charset="iso-8859-1"
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
      <head>
      </head>
      <body style="width:90%; margin-left: 5%; margin-right: 5%" bgcolor="#FFFFFF">
      <!-- HTML Formatted Log Goes In Here -->
      </body>
    </html>
    
  • Thanks Greg - I'll give that a try!
  • Greg,

    I tried the following using GMail, and it's not working as expected. Perhaps I'm doing something wrong...
    cEMailBody = "'MIME-Version: 1.0'"
    cEMailBody = "cEMailBody,'Content-Transfer-Encoding: 7bit'"
    cEMailBody = "cEMailBody,'Content-Type: text/html; charset="iso-8859-1"'"
    cEMailBody = "cEMailBody,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">'"
    cEMailBody = "cEMailBody,'<html>'"
    cEMailBody = "cEMailBody,'  <head>'"
    cEMailBody = "cEMailBody,'  </head>'"
    cEMailBody = "cEMailBody,'  <body style="width:90%; margin-left: 5%; margin-right: 5%" bgcolor="#FFFFFF">'"
    cEMailBody = "cEMailBody,'  <p><span style="color:#000080;"><span style="font-family: trebuchet ms,helvetica,sans-serif;">Here is yesterday&#39;s log file.</span></span></p>'"
    cEMailBody = "cEMailBody,'  <p>&nbsp;</p>'"
    cEMailBody = "cEMailBody,'  </body>'"
    cEMailBody = "cEMailBody,'</html>'"
    
    SMTP_SEND(dvIP_GMail_Connection, sendto, 'Daily Pool Log', cEMailBody, NULL_STR)
    

    When I look at the original e-mail source via Google's webmail, I see the following:
    MIME-Version: 1.0
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    
    MIME-Version: 1.0
    Content-Type: text/html
    <=21DOCTYPE HTML PUBLIC =22-//W3C//DTD HTML 4.0 Transitional//EN=22 =22ht=
    tp://www.w3.org/TR/REC-html40/loose.dtd=22>
    <html>
      <head>
      </head>
      <body style=3D=22width:90%; margin-left: 5%; margin-right: 5%=22 bgcolo=
    r=3D=22=23=46=46=46=46=46=46=22>
      <p><span style=3D=22color:=23000080;=22><span style=3D=22font-family: t=
    rebuchet ms,helvetica,sans-serif;=22>Here is yesterday&=2339;s log file.<=
    /span></span></p>
      <p>&nbsp;</p>
      </body>
    </html>
    

    I'm not sure why that first header showing text/plain is showing up there, but that seems to be dictating the format of the e-mail. Any ideas on how to override that?

    Thank you for your help!


    Mark
  • ericmedleyericmedley Posts: 4,177
    mludviksen wrote: »
    Greg,

    I tried the following using GMail, and it's not working as expected. Perhaps I'm doing something wrong...
    cEMailBody = "'MIME-Version: 1.0'"
    cEMailBody = "cEMailBody,'Content-Transfer-Encoding: 7bit'"
    cEMailBody = "cEMailBody,'Content-Type: text/html; charset="iso-8859-1"'"
    cEMailBody = "cEMailBody,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">'"
    cEMailBody = "cEMailBody,'<html>'"
    cEMailBody = "cEMailBody,'  <head>'"
    cEMailBody = "cEMailBody,'  </head>'"
    cEMailBody = "cEMailBody,'  <body style="width:90%; margin-left: 5%; margin-right: 5%" bgcolor="#FFFFFF">'"
    cEMailBody = "cEMailBody,'  <p><span style="color:#000080;"><span style="font-family: trebuchet ms,helvetica,sans-serif;">Here is yesterday&#39;s log file.</span></span></p>'"
    cEMailBody = "cEMailBody,'  <p>&nbsp;</p>'"
    cEMailBody = "cEMailBody,'  </body>'"
    cEMailBody = "cEMailBody,'</html>'"
    
    SMTP_SEND(dvIP_GMail_Connection, sendto, 'Daily Pool Log', cEMailBody, NULL_STR)
    

    When I look at the original e-mail source via Google's webmail, I see the following:
    MIME-Version: 1.0
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    
    MIME-Version: 1.0
    Content-Type: text/html
    <=21DOCTYPE HTML PUBLIC =22-//W3C//DTD HTML 4.0 Transitional//EN=22 =22ht=
    tp://www.w3.org/TR/REC-html40/loose.dtd=22>
    <html>
      <head>
      </head>
      <body style=3D=22width:90%; margin-left: 5%; margin-right: 5%=22 bgcolo=
    r=3D=22=23=46=46=46=46=46=46=22>
      <p><span style=3D=22color:=23000080;=22><span style=3D=22font-family: t=
    rebuchet ms,helvetica,sans-serif;=22>Here is yesterday&=2339;s log file.<=
    /span></span></p>
      <p>&nbsp;</p>
      </body>
    </html>
    

    I'm not sure why that first header showing text/plain is showing up there, but that seems to be dictating the format of the e-mail. Any ideas on how to override that?

    Thank you for your help!


    Mark


    Maybe I'm missing something but by what your code says your message ends up being:
    cEMailBody,'</html>

    I'm guessing you're trying to put in line feeds. Here's what that should look like:
    cEMailBody = "'MIME-Version: 1.0',$0d,
    'Content-Transfer-Encoding: 7bit',$0d,
    'Content-Type: text/html; charset="iso-8859-1"',$0d,
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">',$0d,
    '<html>',$0d,
    '  <head>',$0d,
    '  </head>',$0d,
    '  <body style="width:90%; margin-left: 5%; margin-right: 5%" bgcolor="#FFFFFF">',$0d,
    '  <p><span style="color:#000080;"><span style="font-family: trebuchet ms,helvetica,sans-serif;">Here is yesterday&#39;s log file.</span></span></p>',$0d,
    '  <p>&nbsp;</p>',$0d,
    '  </body>',$0d,
    '</html>' ,$0d,$0a "
    
  • GregGGregG Posts: 251
    I'm guessing that you are using the built-in NetLinx SMTP functions, and it appears that it forces the text/plain headers out before the data you give it. I've been using the old mail module I've had since well before that function was added, so I don't have that issue (but it doesn't support TLS).

    I guess the first thing I'd try in your case is to leave off "MIME-Version: 1.0" from the text you are sending, and also add two line feeds after the type like so: "'Content-Type: text/html',10,10" and hope that the email client takes this as an override.

    If that doesn't work you may be out of luck.
  • ericmedleyericmedley Posts: 4,177
    Wyeth, he may have to roll his own SMTP client and keep it non-SSL and then he can build the email whichever way he wants. The protocol is not too bad.
  • ericmedley wrote: »
    Maybe I'm missing something but by what your code says your message ends up being:


    Eric,

    Thanks for the reply. I think the variable cEMailBody ended up containing what I expected based on what the message contained - but I didn't do it in the most efficient way. Honestly, I wasn't sure how to handle continuing a long line of code onto another line in Netlinx. Some languages require a continuation character like a "_", and I didn't know how to handle it so I punted. I basically had multiple lines of code that said variable = "a", variable = variable + "b", so then variable = "ab".

    I think the question is whether or not the SMTP_SEND automatically inserts the text/plain header and if there is any way to override it. I would like to use GMail, so I'm stuck with TLS.


    Mark
  • GregG wrote: »
    I'm guessing that you are using the built-in NetLinx SMTP functions, and it appears that it forces the text/plain headers out before the data you give it. I've been using the old mail module I've had since well before that function was added, so I don't have that issue (but it doesn't support TLS).

    I guess the first thing I'd try in your case is to leave off "MIME-Version: 1.0" from the text you are sending, and also add two line feeds after the type like so: "'Content-Type: text/html',10,10" and hope that the email client takes this as an override.

    If that doesn't work you may be out of luck.

    Greg,

    I tried what you suggested, but unfortunately it did not override the settings. The e-mail I received showed the format text and HTML as the text of the message. Here's what the "original" (raw) message looks like from the GMail Web App:
    MIME-Version: 1.0
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    
    Content-Type: text/html
    
    <=21DOCTYPE HTML PUBLIC =22-//W3C//DTD HTML 4.0 Transitional//EN=22 =22ht=
    tp://www.w3.org/TR/REC-html40/loose.dtd=22>
    <html>
      <head>
      </head>
      <body style=3D=22width:90%; margin-left: 5%; margin-right: 5%=22 bgcolo=
    r=3D=22=23=46=46=46=46=46=46=22>
      <p><span style=3D=22color:=23000080;=22><span style=3D=22font-family: t=
    rebuchet ms,helvetica,sans-serif;=22>Here is yesterday&=2339;s log file.<=
    /span></span></p>
      <p>&nbsp;</p>
      </body>
    </html>
    

    I found some open source SMTP/TLS code online, but it sure would be nice if AMX had the functionality built-in.

    http://www.matrixssl.org/index.html
    http://www.codeproject.com/Articles/98355/SMTP-Client-with-SSL-TLS

    Mark
  • GregGGregG Posts: 251
    The hard part for netlinx is the TLS encryption, not the email protocol.

    For email purposes, this is probably do-able, since emails don't have to happen at real-time speeds. But this would definitely require using java/duet because the netlinx language itself might spend forever trying to handshake a TLS connection and timeout before it can even begin. (Assuming you were determined enough to attempt implementing the algorithm that way :-)

    There is some degree of TLS support in Duet, but it's not documented, so it may break when things change - like a lot of my stuff did when the firmware went from 3 to 4.
  • GregG wrote: »
    I'm guessing that you are using the built-in NetLinx SMTP functions, and it appears that it forces the text/plain headers out before the data you give it. I've been using the old mail module I've had since well before that function was added, so I don't have that issue (but it doesn't support TLS).

    I guess the first thing I'd try in your case is to leave off "MIME-Version: 1.0" from the text you are sending, and also add two line feeds after the type like so: "'Content-Type: text/html',10,10" and hope that the email client takes this as an override.

    If that doesn't work you may be out of luck.

    Hey Greg,

    I'm working with this module as well, however my problem is my timestamp is incorrect. I am sending emails at 1pm, and it's showing it was sent at 6:00am. Is this something in the module I can correct?

    Thank you,
    Matt
  • GregGGregG Posts: 251
    I usually just refer to the time in my email client (gmail) which says when I received the email rather than when the sender says they submitted it.

    If you have the source (mine is an include file called EmailOut.axi), you can just edit the part where it adds the Date: header like:

    "Date: Fri, 06 Mar 2015 12:05:50 -0600"

    and make sure it is appending the correct offset from UTC.

    In my file it is on line 178 and it doesn't actually include the offset at all:
    SmtpMessageBuffer = "'Date: ',DAY,' ',DATE,' ',TIME,13,10"
    

    So you could change it to:
    SmtpMessageBuffer = "'Date: ',DAY,' ',DATE,' ',TIME,' -0600',13,10"
    
    to get a -6 hour offset from UTC propagated along to the recipient.

    If you are using the i!-EquipmentMonitorOut.axi ( http://www.amx.com/techcenter/downloadConfirm.asp?fn=/assets/applicationFiles/i!-EquipmentMonitorSetup.exe ) there is a function you can call to set your timezone in the email called SmtpSetTimeOffset(CHAR
    Offset[]) - just pass it in like SmtpSetTimeOffset("'-0600'")
  • Help with ICS file

    Anyone ever have luck creating an .ICS file and attaching it via the email? I'd like to attach a meeting invite as my email attachment.
  • I wrote my own SMTP mail engine and that could send attachments.........I guess you'd have to just know the format of the ICS file, save it as a file on the flash card and then attach it to get this to work. Never tried it with exchange or anything other than SMTP.....
  • PhreaKPhreaK Posts: 966
    The ICS format is pretty straightforward. Writing the file is as simple as writing out to any file from within NetLinx. You will need to implement your own way of sending it though. Last time I tried the internal mail support you could only send *.txt attachments.
  • PhreaK wrote: »
    The ICS format is pretty straightforward. Writing the file is as simple as writing out to any file from within NetLinx. You will need to implement your own way of sending it though. Last time I tried the internal mail support you could only send *.txt attachments.

    Ahh, interesting. I guess I won't waste anymore time on this if I cannot attach the .ics file with my email. :-/
Sign In or Register to comment.