Send a file as an email attachment with high priority (remote webcam photo logger application)
Use the low-level Simple Mail Transport Protocol (SMTP) VIs create an email, attach a file, and set the email header to flag the message as 'high priority' in the recipient's email application. The illustrative application example captures webcam images at regular intervals and sends them as email attachments.
Use cases
Event detection – Academic RIO Device monitors a webcam for a feature of interest to occur, captures an image of the event, and emails the image
Remote data logging – Device monitors environmental conditions through one or more sensors, stores the measurements to a log file, and forwards the log file by email to one or more recipients either on demand or periodically
Features
A complete implementation of the Simple Mail Transfer Protocol (
SMTPSimple Mail Transport Protocol, a standard for Internet-based email systems.
) standard including email attachments, CC and BCC recipients (carbon copy and blind carbon copy), and email headers such as importance, delivery request receipt, and read request receipt
Relatively easy to code; see the “Send Email” Express VI for even greater simplicity when you simply need to send some text
Implements TLS (Transport Layer Security) to ensure the secure (private) transmission of email, which is often required by modern SMTP servers
Keep in mind
You must designate a 3rd-party SMTP server such as Google Gmail or one provided by your own Internet Service Provider (ISP); LabVIEW does not implement its own SMTP server
No built-in support to receive email
IMPORTANT: The Academic RIO Device system date must be reasonably close to the true date for TLS-secured email to be accepted by the SMTP server. Experiments with the Gmail SMTP server show that the Device system date must be no more than 12 days in the past and no more than 70 days into the future. The Device does not include an onboard real-time clock (RTC), therefore its system date resets to the same date on each power cycle. While it is possible to occasionally manually update the power-on system date (see below), consider the inexpensive Digilent I2C battery-backed RTC module to preserve the true calendar date across power cycles.
You can adjust the power-on system date with NI MAX or a browser.
LabVIEW block diagram elements
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Connect your Academic RIO Device to your PC using USBLAN, Ethernet, or Wi-Fi. NOTE: Not all Academic RIO Devices have Ethernet and Wi-Fi connectivity options.
Connect a USB webcam and a USB thumbdrive; you will need to use either a generic USB hub or the Stratom
X-HUBCombination USB and Ethernet hub for myRIO
to expand the number of available USB ports
Download and unpack the
rt_email-advanced.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_email-advanced.zip (for use with NI ELVIS III)
archive, and then double-click the ".lvproj" file to open the project. NOTE: This project was written for a NI myRIO 1900 or NI ELVIS III connected by USBLAN at IP address 172.22.11.2.
If you are using a different IP address or another Academic RIO Device (Example: NI myRIO 1950 or NI RIO Control Module) do the following:
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Open the “acquire image and send” VI block diagram
Locate the “email setup info” area and enter the following information:
“from” = your Google Gmail account, e.g., “myaccount@gmail.com”
“username” = Google account username, e.g., “myaccount”
“password” = Google account password
“recipient” = email address of one recipient
CAUTION: This VI stores your Google account credentials – keep this in mind when posting or sharing your code!
Open “RT Main” and enter a value for the image acquisition interval
Run (Ctrl+R) the VI:
The VI continually acquires images from the USB webcam at the interval you specified.
The VI saves the image to disk (the USB thumbdrive) in JPEG format with the timestamp embedded in the filename, and sends the image as an attachment to the email recipient.
LED0 turns on when the image acquisition begins and turns off again after the email has been sent.
Press the onboard pushbutton to manually acquire and send an image.
Confirm that you successfully receive the emails, that the email body shows the time and date at which the image was acquired, and that the attachment is the correct image.
View the thumbdrive contents by browsing to http://172.22.11.2/files/u/ and confirm that you can see a number of “webcam_MM-DD-YYYY_HH.MM(SS).jpg” files.
Stop (Ctrl+.) the VI when you are finished.
Troubleshooting tips
Problems accessing the webcam – Open the block diagram of the “acquire image and send” VI and double-click the “Vision Acquisition” Express VI. Click the refresh button (pair of green arrows) to search for your connected camera, select it, and then click the image preview button (blue arrow) to confirm that you can properly access the camera. Click through the remaining dialog boxes to adjust other camera settings, and then click “Finish” when done. Save and close the VI.
Refer to the trouble-shooting section of “Send Email” Express VI for additional likely error messages and remedies