5

I'd like to get started on a project involving the arduino and email notifications. I'm not sure anything like this has been done before, but I'm guessing some form of it has. Let me explain. Basically I would like to set up the arduino with either some piezo sensors or a kinect so that when an action is performed (or pressure is sensed) an email (or tweet) will automatically be sent. I'm sure this can be done, but I'm not sure where to start and I wondering if anyone had an idea? Thanks in advance.

1
  • I want to do something similar (I want an email or tweet of temperature readings). How is your Arduino going to communicate with your network? Are you using an Ethernet shield? Wifi? Good luck!
    – Lisa
    Aug 1, 2012 at 20:25

3 Answers 3

1

I haven't tested the below code, but this is the most basic structure for what you're trying to do.

On the Arduino, set setup your code to output something on the serial line ("arduino_output") when you want to send an e-mail. Then on the computer, wait for that event.

Linux is really easy because a serial port can be treated the same as reading a file.

#!/usr/bin/perl
use open ':std';
use MIME::Lite;

#Open the COM port for reading
#just like a file
open FILE, "<", "/dev/usbTTY0" or die $!;

#setup e-mail message
$msg = MIME::Lite->new(
    From        => '"FirstName LastName" <[email protected]>',
    To          => "[email protected]",
    Subject     => "subject",
    Type        => "text/plain"
);

#loop forever (until closed w/ ctrl+c)
while (1){
    while (<FILE>){
        # if there is output from the arduino (ie: Serial.write(...))
        # then the e-mail will be sent
        if ($_ == "arduino_output"){
            MIME::Lite->send('smtp','mailrelay.corp.advancestores.com',Timeout=>60);
            $msg->send();
        }
    }  
}

Good luck on your project.

0

i'd recommend to use Pyserial

then from arduino you'd just send a data to python

void setup(){
  Serial.begin(9600);
}
void loop(){
  if (EVENT BECOME TRUE /* sensor value or whatever */){
    Serial.write("Send mail");
  }
}

then form python { after installing pyserial }

import serial
import smtplib
def sendMail(receiver,message):
    try:
        s=smtplib.SMTP_SSL()
        s.connect("smtp.gmail.com",465)
        s.login("[email protected]", "Password")
        s.sendmail("[email protected]", receiver, message)#write the destination at receiver parameter  
    except Exception,R:
            print R

ser = serial.Serial('/dev/tty.usbserial', 9600)# or in windows you could write port name
while 1:
  receive = ser.readline()
  if receive == "send mail":sendMail("[email protected]","YOU got mail from arduino!")

well you could change smtp according to your MAIL host , in my case i've used gmail , good luck in your project :D

0

It's very simple to check mail with arduino!

I wrote a post here http://www.albertopasca.it/whiletrue/arduino-mail-notifier-with-c/
to use C# on windows to check gmail mail.

You can adapt the code to use it on every OS that you want.

hope this helps.

1
  • have you done anything close to using an ssl library to use gmail smtp for sending email from an arduino?
    – aVC
    Dec 21, 2015 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.