RaspiEmail
Here are the notes for reading email from a Python script:
Reading Email:
The example below works on Python2.
Note that you have to put a BLANK LINE between text for it to show up on a separate line.
GMAIL has to be set to only forward POP mail from <now>, or it forwards ALL email messages (read, filed, or inbox).
http://www.codemiles.com/python-tutorials/reading-email-in-python-t10271.html
import poplib
mailServer = 'pop.gmail.com'
emailID = 'example@gmail.com'
emailPass = 'xxxx'
## open connection to mail server (Secured using SSL)
myEmailConnection = poplib.POP3_SSL(mailServer)
## print the response message from server
print myEmailConnection.getwelcome()
## set email address
myEmailConnection.user(emailID)
## set password
myEmailConnection.pass_(emailPass)
## get information about the email address
EmailInformation = myEmailConnection.stat()
print "Number of new emails: %s (%s bytes)" % EmailInformation
## Reading an email
print "\n\n===\nRead messages\n===\n\n"
## Read all emails
numberofmails = EmailInformation[0]
for i in range(numberOfMails):
for email in myEmailConnection.retr(i+1)[1]:
print email
- See more at: http://www.codemiles.com/python-tutorials/reading-email-in-python-t10271.html#sthash.qYlbueoo.dpuf
Sending email:
The following web page has a working example: http://rpi.tnet.com/project/faqs/smtp
Get these packages:
sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo apt-get install mpack
sudo nano /etc/ssmtp/ssmtp.conf
In that file, edit or add these lines:
AuthUser=youruserid@gmail.com
AuthPass=userpass
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
Now you can send mail with the unix command:
mail -s "this subject" userid@gmail.com < input_file
Looks like Gmail uses port 465, but yahoo uses port 587 instead of 465(?).
"IT seems that the problem may be that I've tried using port 465 instead of 587. In the google help it says that 465 is SMTP with SSL and 587 is SMTP with TLS (whatever those are "