Sending Email from Python
Python has a library for Simple Mail Transfer Protocol(SMTP) that can be used to send gmail from your pi.
import smtplib
GMAIL_USER='your_name@gmail.com'
GMAIL_PASS='your_password'
SMTP_SERVER='smtp.gmail.com'
SMTP_PORT=587
def send_email(recipient, subject,text):
smtpserver=smtplib.SMTP(SMTP_SERVER,SMTP_PORT)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(GMAIL_USER,GMAIL_PASS)
header='To:' + recipient +'\n' +'From: '+ GMAIL_USER
header=header + '\n' +'Subject:' +subject +'\n'
msg=header +'\n'+ text + ' \n\n'
smtpserver.senmail(GMAIL_IUSER, recipient, msg)
smtpserver.close()
send_email('destination_email_address', sub', 'this is text')
To use the code change the variables GMAIL_USER, GMAIIL_PASS to match your email credentials. If you are not using Gmail then you will need to change the values of the SMTP_SERVER and even the port.
Also change destination and the text you wish to send.
