Gabriella Levine

ongoing and past work

RWEL – smtp and IMAP libraries

I used this code to send an email:

import smtplib  
fromaddr = ''  
toaddrs  = ''  
msg = 'There was a terrible error that occured and I wanted you to know!'  
# Credentials (if needed)  
username = ''  
password = 'qwewqwe1!'  
# The actual mail send  
server = smtplib.SMTP('')  
server.sendmail(fromaddr, toaddrs, msg)  

I would like to be able to monitor a project I’m doing for Sustainable energy (where I will be monitoring the voltage input from a solar panel), and send myself an email if any of the components (the Arduino, the Xbee, the Real time clock, the sd card / shield) stops functioning properly

I thought using this code and the smtp library would send an email but I KEEP getting an error(see below), and I’m not quite sure why yet:

import smtplib
from email.mime.text import MIMEText

sender = ''
recipients = ''

msg = MIMEText('hi my name is gabby')
msg['Subject'] =  'test'
msg['gabriella levine'] = sender
msg['you'] = recipients

smtpserver = ''
smtpuser = 'gabriella.levine'         # set SMTP username here
smtppass = 'qwewqwe1!'   # set SMTP password here

session = smtplib.SMTP("", 587)

session.login(smtpuser, smtppass)

smtpresult = session.sendmail(sender, [recipients], msg.as_string())

if smtpresult:
  errstr = ""
  for recip in smtpresult.keys():
      errstr = """Could not delivery mail to: %s

Server said: %s

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
  raise smtplib.SMTPException, errstr



Traceback (most recent call last):
File “”, line 1, in
import smtplib
File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/”, line 46, in
import email.utils
File “/Users/administrator/Desktop/pyEmail/”, line 25, in
conn.login( “putemailhere”, “putpasswordhere” )
File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/”, line 501, in login
raise self.error(dat[-1])
imaplib.error: [AUTHENTICATIONFAILED] Invalid credentials (Failure)

I also started trying to sort through email using the IMAP library – I haven’t gotten very far, and have to look at the documentation some more, but this is what I have:

import sys
import imaplib

conn = imaplib.IMAP4_SSL("", 993)
conn.login('gabriella.levine', 'qwewqwe1!')
output ="INBOX")
print "new messages", output
#toaddress = msg['to']
#output1 ="SENT MAIL")
#print output1'Sent')
print output1

Leave a Reply