Mail Relays using python
June 6, 2013 1 Comment
I recently needed to send e-mail from my home computer in a python script. Unfortunately I use Comcast and they have decided that anyone that does this is a spammer so they have blocked all outbound communication over port 25. Big thanks to Lars for pointing me in the right direction!
In order to get around this both gmail and godaddy provide relay services.
Here is the solution:
Create the message
sender = 'ghoti@cultureofqualityengineering.com' #you will need to use your email of course password = 'MyPassword' receiver = #submitted email address message = """From: Geoff <""" + sender + """> To: To Person <""" + email + """> Subject: Kapow! Hey thanks for using this service! and other interesting text """
Send the message
try:
#session = smtplib.SMTP('smtp.gmail.com',587) #for gmail uncomment this
#session = smtplib.SMTP_SSL('smtpout.secureserver.net',465) #for godaddy uncomment this line
session.ehlo()
#session.starttls() #uncomment for gmail
#session.ehlo() #uncomment for gmail
session.login(sender, password)
session.sendmail(sender,receiver,message)
session.quit()
except smtplib.SMTPException:
print "Error: unable to send email"