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 instruction doesn't work


FelipeSerra Nov 14, 2013 06:18 PM

Hello everyone. I made the following piece of code that should enable my CR1000 to send a data table to a certain email. I tried it, but it doesn't work, so I'm probably missing something. I'm using a NL115 to connect my CR1000 to the office network. I'm using no modem for now.

Any help with this would be very appreciated.


'Declare Variables and Units
Public BattV
Public PTemp_C
Public message As Boolean
Public msgsent As String
Public send

Units BattV=Volts
Units PTemp_C=Deg C

'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,30,Sec,10)
Sample(1,BattV,FP2)
Average(1,PTemp_C,FP2,False)
TableFile("USR:datatable",0,-1,0,30,Sec,0,0)
EndTable

'Main Program
BeginProg
Scan(5,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Wiring Panel Temperature measurement PTemp_C
PanelTemp(PTemp_C,_50Hz)
'Call Data Tables and Store Data
CallTable(Table1)
If TimeIntoInterval(0,2,Min)
send = true
EndIf
NextScan

SlowSequence
Scan(1,Min,3,0)
If send Then
message = EMailSend("smtp.googlemail.com:465","[receiver]@gmail.com","[sender]@gmail.com","New file has arrived","Open attachment","USR:table","[sender]@gmail.com","[password]",msgsent)
send = false
EndIf
NextScan
EndSequence
EndProg


jtrauntvein Nov 15, 2013 01:54 PM

Sam wrote the following thread regarding gmail:

http://www.campbellsci.com/forum/messages.cfm?threadid=D356F355-FB92-4228-8ECD4EFE415DF117

Is your OS up to date?


aps Nov 15, 2013 02:26 PM

You should also be aware that Google have been clamping down on security in recent months and are introducing 2-stage login verification and "application specific passwords". The application specific password is what you would need to use to send emails from a datalogger. That password is different to your normal Google log in and has to be setup online.

I am not sure if and when they are forcing a changeover to this security but it is worth checking your account settings.


Sam Nov 16, 2013 02:23 AM

You should also use port 587 instead of 465.


MPPMC Nov 19, 2013 02:27 PM

Felipe, did you get this working?

A couple of questions for you:

I use gmail with my loggers and don't include the port number in the server address; it's just "smtp.gmail.com" - have you tried this?

Is TLS enabled on the logger (Device Config Utility - Advanced)?

Are you aware that the attachment you're trying to attach doesn't match with the TableFile instruction? It should read "USR:Datatable.dat". I've had emails fail to send when the attachment was invalid.

What result code do you get for 'message' and 'msgsent'?

The result code for Emailsend should end on a 221 from Gmail's servers. I parse it as follows:

SplitStr (EmailResult(2),EmailResult(1),"",2,0)
If EmailResult(2) = "221" Then EmailSent = True

(EmailResult is a string of 50 length and arrayed to 3 (EmailResult(3) * 50)). See what result code you're getting and have a look here:
http://email.about.com/cs/standards/a/smtp_error_code_2.htm


Michael


Frankwin Feb 13, 2014 12:21 AM

I've been working on doing almost exactly what you are trying to do, Felipe.
In addition to the above comments, I'd like to add that another problem I see (and I'm battling with it at the moment,) is the filename you are trying to send.
In the Tablefile instruction, you are creating a file named "USR:datatable".
However, you can't use this name in the Emailsend instruction because it will ACTUALLY be saved as "USR:datatableX.dat"
Where X is incremented from 0 on upwards on each iteration of the Tablefile instruction.
So, I'm guessing you'd have to do something complicated like assembling a new filename string, with an incremented name.

Initially I tried using the "Lastfilename" parameter in the Tablefile instruction (you've used a 0 there, ie, it's ignored). This works, but it lags one scan behind, which isn't such a problem if it is just one hour behind say, but no good if it is one day or 7 days behind.

So I'm still working on that one.

Frank


Dana Feb 14, 2014 12:13 AM

Hello Frank,

You can manipulate what is sent with regards to a filename by using the Mid function within the instruction. I use this in the FTPClient instruction, which has similar parameters as EmailSend:

FTPClient (IPAddress,UserName,Password,lastfilename,Mid(LastFileName,5,20),0)

This will store the file on the remote with a name that starts 5 characters in from the original name, thus, effectively stripping off the USR:

I hope this is helpful.

Dana W.


Frankwin Apr 14, 2014 01:25 AM

Thanks Dana. That's certainly helpful, although I had come up with a slightly different solution myself.

A MAJOR problem I'm having right now in getting my emails to send relates to TLS or transport layer security.
Experimentally, I've found that an internet connection (for logging into Gmail) will only succeed if TLS is OFF. However, under TLS setting in DEVCONFIG, there is a note saying that TLS is required when using Gmail for email. For this reason, it says, TLS gets turned on automatically when you upload a program that contains the Emailsend function.
Initially, I found this wasn't the case; I could turn TLS off before or after sending such a program and it would stay off. Now, however, I've found that it keeps turning itself back on and I can't send emails anymore.


Frankwin May 14, 2014 02:16 AM

Update: Have now got this working. TLS does need to be on, and it will automatically be turned on.
I think the settings in some of my older modems were wrong.

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