Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

EmailSend and TLS


cunningham Jan 6, 2011 02:33 PM

hi all,

i am using a cr1000 OS21.
I want to send email (via NL115 while debugging and via Modem/PPP when deployed).
I experience some problems while using the EMailSend function (in a slowsequence) with an attachment.

SMTP: smtp.1und1.de:25 / TLS
SMTP : smtp.googlemail.com:25 / TLS

When using smtp.1und1.de usually the first or second attempt does work, but after next EmailSend the logger occasionally locks up in 2 possible ways.

1. The logger locks up and reboots
2. The Logger does not "return" from EmailSend.

With smtp.googlemail.com it seems to work better but i also have some reboots. Sometimes i get an SSL-Write error. Preceded by a "failed alloc pkt" in IPTrace

I have only seen this, when i have an attachment added.

As the manual does not give any hints regarding TLS i am trying around with DevConfig.

In DevConfig set TLS to 1.
TLS-Certificate : empty
TLS-PrivateKey : empty
TLS-KeyPassword : empty


TLS-Certificate : cr1000.crt (also tried CPU:cr1000.crt)
TLS-PrivateKey : cr1000.key (also tried CPU:cr1000.key)
TLS-KeyPassword : ****

Crt and Key created with:
openssl req -new -x509 -nodes -out cr1000.crt -keyout cr1000.raw.key
Added password to key
openssl rsa -des3 -in cr1000.raw.key -out cr1000.key

Both configurations show same behaviour.
Can anyone give an example of failsafe usage?
When do i need to provide crt- and key-files.
Whats the syntax?

I have no real clue about email. It would be great if someone could give me some hints.

Other questions:
How long can the string be that i can pass to the EmailSend function? Is it ok to declare the string as string*4096?

I have also seen the 1und1 smtp server answering with "500 Line limit exceeded". The email message itself was only about 350 Byte and the attachment had only 80 Lines a 150Bytes.
Any idea where this comes from?

greets


Sam Jan 11, 2011 06:26 AM

cunningham,

In regards to sending an email via a server required TLS authentication, you only need to toggle the TLS enabled flag to true (<>0).

When using TLS it can take 20 to 40 seconds to authenticate and send even a small message. That is why I try to always put the email process in it's own SlowSequence. I don't want it to hold up my other scans/sequences.

I have used email messaging requiring TLS authentication (mainly via GMail) in many applications and I have not experienced the lock up symptoms you've described.

My applications have only required very small message bodies. However, some of them have required attaching large image and data files.

Here is an example program using the EmailSend function:

Public PTemp, batt_volt
Public SendEmail As Boolean
Public EmailCounter
Const EmailHost = "smtp.gmail.com:587"
Const EmailUser = "user@gmail.com"
Const EmailPass = "password"
Public EmailSubject As String * 127
Public EmailMsg As String * 127
Public EmailTo As String * 31 = "email@email.com"
Public EmailSuccess As Boolean
Public EmailResult As String * 63

BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)
NextScan

'Slow Sequence For Handling Email Sending
SlowSequence
Do While TRUE
If SendEmail Then
EmailCounter = EmailCounter + 1
EmailSubject = "Test " + EmailCounter
EmailMsg = "This is a test email."
EmailSuccess = EMailSend (EmailHost,EmailTo,EmailUser,EmailSubject,EmailMsg,"",EmailUser,EmailPass,EmailResult)
SendEmail = FALSE
EndIf
Delay (1,1,Sec)
Loop
EndSequence

EndProg

* Last updated by: Sam on 1/11/2011 @ 1:18 PM *


Sam Jan 11, 2011 09:41 PM

cunningham,

Using the program below and OS.20 and OS.21, I have been able to recreate some of the symptoms you described. It appears to follow the size of the email message body (note I did not investigate attachment sizes).

The most common symptom I experienced was the email process trigging a watchdog and causing the logger to reboot. CompileResults in the Status table confirm this with a "Warning" explaining that the logger has recovered from a "Watchdog timer Out of Memory"

One of our colleagues from the UK (Andrew) noted that he has experienced similar behavior and that Engineering is looking into the problem and working on a fix.

So, for now I'm afraid that you need to limit the size of the body and attachments. I started to consistently run into problems with email message body sizes exceeding 850 characters.

-------------------------------

Public SendEmail As Boolean
Public EmailCounter
Public StrLen
Const EmailHost = "smtp.gmail.com:587"
Const EmailUser = "user@gmail.com"
Const EmailPass = "password"
Public EmailSubject As String * 31
Dim EmailMsg As String * 10000
Public EmailTo As String * 31 = "email@email.com"
Public EmailSuccess As Boolean
Public EmailResult As String * 63

BeginProg
Scan (60,Sec,0,0)
SendEmail = TRUE
NextScan
SlowSequence
Do While TRUE
If SendEmail Then
EmailCounter = EmailCounter + 1
EmailSubject = "Test " + EmailCounter
StrLen = Len(EmailMsg)
If StrLen < 9000 Then
EmailMsg = EmailMsg + CHR(13) + EmailCounter + ": Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut"
EmailMsg = EmailMsg + "labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
EmailMsg = EmailMsg + "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + CHR(13)
EndIf
EmailSuccess = FALSE
EmailResult = ""
EmailSuccess = EMailSend (EmailHost,EmailTo,EmailUser,EmailSubject,EmailMsg,"",EmailUser,EmailPass,EmailResult)
SendEmail = FALSE
EndIf
Delay (1,1,Sec)
Loop
EndSequence
EndProg

* Last updated by: Sam on 1/11/2011 @ 2:43 PM *


cunningham Jan 12, 2011 10:07 PM

hi

Thanks, this is quite useful to know.
After shortening the body everything works fine.

Is there any information when/how to use the certificate settings that are accessible via DevConfig?


jtrauntvein Jan 13, 2011 07:48 PM

The certificate/private key settings that are there are meant to address the ability of the datalogger to act as a TLS server. During TLS negotiations, a server can require the client to transmit a certificate but these cases are rare.

At present, the only time where an application would require a certificate to be present is when the datalogger program has a DNP3() instruction present that specifies a port number of 20000 (used for DNP3/Secure).


cunningham Jan 17, 2011 09:30 AM

thanks jtrauntvein for for making this clear.

greets


Sam Jan 17, 2011 09:42 PM

Cunningham,

I just wanted to let you know that I've been testing a beta version of our next OS release. With it I have successfully sent hundreds of emails with body's containing over 500 to 30,000 characters. I did not try to find the upper limit. So, you will probably be very interested in our next OS release - I do not know when that will occur.

Sam


cunningham Jan 18, 2011 11:36 AM

hooray!

thats good news.
I am looking forward to the the next release.

Log in or register to post/reply in the forum.