Thursday, January 2, 2014

Sending email with the Arduino Yun

See thread http://forum.arduino.cc/index.php?topic=187319.msg1414629#msg1414629

In summary:

install the ssl stuff for python:

opkg update
opkg install python-openssl

next you can send mails as follows (using gmail smtp)


#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
import private.pw

USERNAME = private.pw.myMailUser
PASSWORD = private.pw.myMailPass
MAILTO  = "something@somewhat.com"

msg = MIMEText('Hello,\nMy name is Yun, \nhow are you')
msg['Subject'] = 'Mail from Yun'
msg['From'] = USERNAME
msg['To'] = MAILTO

server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO, msg.as_string())
server.quit()

The username and passwords are stored in the file pw.py in subdir private

No comments:

Post a Comment