Sending Email from Your Data Logger Just Got Easier!

by Dana Worley | Updated: 01/25/2017 | Comments: 8

Search the Blog


Subscribe to the Blog

Set up your preferences for receiving email notifications when new blog articles are posted that match your areas of interest.


Area / Application

Product Category

Activity

Corporate / News

Enter your email address:



Suggest an Article

Is there a topic you would like to learn more about? Let us know. Please be as specific as possible.

Leave this field empty

datalogger sending email

Have you had problems finding an SMTP server to use to send emails from your data logger? Are compatibility issues causing you to look for a work-around? Keep reading for a solution that may be just what you need.

Some Background

In 2006, we added the ability in our operating systems for IP-enabled data loggers to send emails using a function called EmailSend() This function opened up a whole new world, giving our data loggers 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 data loggers 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.

Our Solution: EmailRelay() Function

To provide a better experience for customers who need to send emails from their data loggers, we introduced the EmailRelay() function with the following data logger 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 100 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.

Example Program

Here's a quick test program to get you started. Just change the constant ToAddr to send an email from your data logger 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 data logger 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() versus EmailRelay()

EmailSend() is still included in the data logger 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 data logger operating systems, leave us a note below!


Share This Article



About the Author

dana worley As the Software Product Manager at Campbell Scientific, Inc., Dana Worley spends her days managing software issues, providing second-tier customer support, and documenting the instruction set for CRBasic data loggers. Occasionally, she can be found commenting on Campbell Scientific’s user forum. Away from the office, Dana enjoys hiking, mountain biking, and playing Fused Glass Artist in her home studio (which requires many bandages!).

View all articles by this author.


Comments

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.

Please log in or register to comment.


We're active on Social Media!
Stay informed with our latest updates by following us on these platforms: