von Dana Worley | Aktualisiert: 01/25/2017 | Kommentare: 19
Have you had problems finding an SMTP server to use to send emails from your datalogger? Are compatibility issues causing you to look for a work-around? Keep reading for a solution that may be just what you need.
In 2006, we added the ability in our operating systems for IP-enabled dataloggers to send emails using a function called EmailSend() This function opened up a whole new world, giving our dataloggers the ability to issue notifications about the status of a station, transfer data files as attachments, or alert someone about an alarm condition.
Over the years we have found that users often have a problem with finding an SMTP server to use. Many customers rely on publicly available free services such as Gmail or Yahoo, but increasingly, these services have added restrictions that prohibit dataloggers from sending emails. Sometimes the fix requires digging through settings to change in the free account, sometimes the fix requires bribing the “IT guy” to make network changes, and sometimes, it can’t be fixed at all.
To provide a better experience for customers who need to send emails from their dataloggers, we introduced the EmailRelay() function with the following datalogger operating systems:
In its simplest form, EmailRelay() has only four parameters:
EmailRelay (ToAddr,Subject,Message,ServerResponse)
The function has additional parameters that let you send attachments or send data directly from a data table, without first writing the data to a file. (We refer to this as “streaming.”)
With EmailRelay() you can send up to 30 emails each day, and each message can be up to 1 M in size (size includes the message overhead, the message itself, and any attachments). The message count is reset on a daily basis.
Tip: When creating and testing a program using EmailRelay(), make sure to use a manual trigger to run the EmailRelay() function, and to set that trigger back to False after execution of the function. This ensures you won’t exceed the daily email limit during the first test run of your program.
Here's a quick test program to get you started. Just change the constant ToAddr to send an email from your datalogger to yourself.
‘declare program variables and constants Const ToAddr="YourEmail@yourcompany.com" Const Subject="Email Message Test" Const CRLF = CHR(13)+CHR(10) Public Batt Public AlarmTrigger As Boolean Public Message As String * 250 Public EmailSuccess Public ServerResponse As String * 50 BeginProg Scan (1,Sec,3,0) Battery (Batt) NextScan SlowSequence Scan(1,sec,1,0) 'Set Alarm Trigger Manually If AlarmTrigger Then Message = "Hello!" + CRLF + CRLF Message = Message + "This is an automatic email message from your friendly datalogger named " + Status.StationName + ". " Message = Message + "An alarm condition has been triggered. " Message = Message + "The battery voltage is " + Batt + " volts." + CRLF + CRLF + CRLF Message = Message + "Datalogger time is " + Status.Timestamp EmailSuccess=EmailRelay (ToAddr,Subject,Message,ServerResponse) AlarmTrigger=False EndIf Erase (Message)'Erase the message after sending NextScan EndProg
Tip: Run EmailRelay() in a SlowSequence, as shown above, to avoid the delay of critical measurements and other important tasks executed in the main scan.
The From Address of the email sent by the datalogger is emailrelay@konectgds.com. Konect GDS is Campbell Scientific's cloud-hosted data collection platform. It is also where the Campbell Scientific email server is hosted.
EmailSend() is still included in the datalogger operating systems. If you are already using the EmailSend() function and it works well for you, there is no need to change. However, if you have struggled with compatibility with your existing SMTP server, give this new function a try. We hope you will find it easier to use.
If you have comments about this new function in the datalogger operating systems, leave us a note below!
Kommentare
ganzlin | 01/25/2017 at 11:41 AM
Thanks for this update. I am on OS 31 on my CR3000s and up to date with the patch on LoggerNet to 4.4.2 but still don't see EmailRelay in the list of commands in CRBasic editor. Also, could you explain what the command CRLF does and an example of a logical operator to trigger an email alert? Thanks
jra | 01/25/2017 at 12:14 PM
Hi ganzlin,
When you download an OS from our web site you need to run the executable to update your CRBasic instructions and Help files. Once you do that you will see EmailRelay() in the instruction list.
CRLF is a carriage return line feed. Back in the old days of typewriters, when the typing mechanism (a carriage) got to the end of a line you had to return it and advance the paper (line feed). Const CRLF = CHR(13)+CHR(10) does that digitally now.
Here's an article on different ways to use time to trigger an action.
Hope that helps,
Janet
ganzlin | 01/25/2017 at 01:15 PM
Thank you that did it!
francesco.sabatini | 02/01/2017 at 08:48 AM
Dear Dana, Thank you for implementing this new function, we found it very useful. We would like to know if there is a limited number of email addresses that can be inserted in the variable "ToAddr" as for your example. Actually we are inserting 4 email adrresses and yesterday it sent the messages only to one of the adddress out 4.
On which basis you calculate the threshold of 30 email per day: by email address or by data logger serial number? There are some filter on the recipients?
Thank you again for your support, ciao
Francesco and Alessandro
Dana | 02/01/2017 at 08:56 AM
Hello Francesco and Alessandro,
The limit of 30 emails per day is based on the datalogger. If you send one email to 5 people, you have used up only one of your emails for the day.
With the EmailRelay function, you can send to multiple email addresses at once. My first guess, without testing, is that the "ToAddr" would need to be a String variable rather than a Constant. I'm currently not at my desk to test, but I will double-check. You can also give it a go and see if you have success.
I'm glad you're finding this new function useful. I think it is a great way to simplify sending email from a Campbell datalogger!
Kind regards, Dana
francesco.sabatini | 02/01/2017 at 11:44 PM
Dear Dana,
thank you so much for your real time reply, much appreciated.
Actually in the present program "ToAddr" has been define as follows:
Const ToAddr = "alessandro.materassi@cnr.it,f.sabatini@ibimet.cnr.it,....+2 recipients"
So we will try to set it as a string variable.
Our best regards from Italy, ciao
Francesco & Alessandro
Memrys | 10/10/2018 at 09:46 AM
Hello,
I cannot seem to find a working version of EmailRelay through any example. Operating on a cr1000 with Std.32.03. Using the above example I obtain a -2 response. Even through CRBasic help and making a few changes does not seem to produce a result. Connection is through a RV50 modem using CSI template.
JDavis | 10/10/2018 at 10:57 AM
The -2 response code means you don't have enough data to send yet. Just wait, and it should work.
JFE2011 | 11/12/2018 at 09:59 AM
Hi,
I have a situation where I want to send an email with data table as an attachment, but only once a week. My understanding is that the slowest a scan sequence can run is once a day. Is there a way of scheduling emailrelay to run once a week?
Thanks
Joel
Dana | 11/12/2018 at 10:25 AM
Hello Joel,
One solution is to trigger EmailRelay based on the result of the RealTime instruction. This is from the help in CRBasic:
The RealTime instruction loads the destination array (Dest argument) with the current time values in the following order: (1) year, (2) month, (3) day of month, (4) hour of day, (5) minutes, (6) seconds, (7) microseconds, (8) day of week (1-7; Sunday = 1), and (9) day of year. The destination array must be dimensioned to 9. The time returned is the time of the datalogger's clock at the beginning of the scan in which the RealTime instruction occurs.
As an example, you could use
If RealTime(8) = 1 and RealTime(4) = 12
To trigger the event to happen every Sunday at noon.
Best, Dana
vadivelrajap | 04/04/2019 at 04:56 AM
in EmailRelay function, is there any possiblity to send attachment.
Dana | 04/04/2019 at 08:35 AM
Yes, the text in the article above shows the mininum number of parameters required for the instruction, but there are additional parameters including an attachment name. From the CRBasic help, here are all the parameters:
EmailRelay ( ToAddr, Subject, Message, ServerResponse, Attach [optional], NumRecs/TimeIntoInterval [optional], Interval [optional], IntervalUnits [optional], FileOption [optional], TimeOut [optional] )
Keep in mind that message size is limited to 1M. This includes the message itself, any overhead, and attachments.
Dana W.
dandersonncwcd | 03/23/2021 at 08:14 AM
Does the EmailRelay function only work with Konect?
Dana | 03/23/2021 at 08:17 AM
EmailRelay uses part of the Konect Server to route messages through, but you do not need to be using KonectGDS.
Best, Dana
brf11 | 03/30/2021 at 07:32 AM
I am not sure where to begin but was advised to use this EmailRelay function and send to IFTTT to transmit a notice to Twitter. Any thoughts and where do I begin?
Dana | 03/30/2021 at 07:51 AM
If you do a search on "email to Twitter feed" you will come across several articles discussing this. However, it's not something I have tried. If you do give it a try, keep us updated on how it goes.
Best, Dana
luisfgranada | 06/26/2023 at 07:41 AM
Hello. I wonder if it's possible to add the date to the name of the attachments when streaming directly from a table, similar to what LoggerNet does when option "File Output Option" is set to "Create Unique File Name". Right now, there are only two options (that I know of): Having an incrementing number added to the file name, this number will reset if you update the datalogger program, or not having this number at all. In both cases, you might end with different emails having different attachments with the same filename, which is not appropriate for automatic process. Thanks
Dana | 06/27/2023 at 04:24 PM
Thank you for reaching out! There is not a way to specify the file name when you are streaming data - only if you are creating a dat file first and sending that. I can convey this suggestion to our product manager for consideration.
Thank you for the input. Best, Dana
luisfgranada | 07/11/2023 at 02:50 PM
Hi Dana. Sorry I didn't reply earlier. I didn't get a notification. That would be wonderful, let's hope they add it to future versions of firmware. Thanks
Please log in or register to comment.