SMTP with Python, can't send emails to domains other than gmail

1k views Asked by At

I'm trying to send an email using a Python script and smtp (I made an account on sendgrid.com), and I found this code on http://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/ and I can make it work just fine for gmail, but no other domain seems to receive their test mail. When I check my email activity on sendgrid.com, it tells me the emails have been dropped or bounced because they aren't RFC 5322 compliant. I tried to google this error, but I just can't seem to find a solution. This is what I have so far:

import smtplib

to = '[email protected]'
user = 'username'
pwd = 'password'
smtpserver = smtplib.SMTP("smtp.sendgrid.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(user, pwd)
header = 'To:' + to + '\n' + 'From: ' + user + '\n' + 'Subject:Test! \n'
print header
msg = header + '\n Test message \n\n'
smtpserver.sendmail(user, to, msg)
print 'Done!'
smtpserver.close()

Feel free to help me out!

0

There are 0 answers