def send_email_direct(email_from, email_to, subject, body):
# find the appropiate mail server
domain = email_to.split('@')[1]
remote_server = get_mx_record(domain)
if (remote_server is None):
print "No valid email server could be found for [%s]!" % (email_to)
return
# connect to remote mail server and forward message on
server = smtplib.SMTP(remote_server, 25)
msg = MIMEMultipart()
msg['From'] = email_from
msg['To'] = email_to
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
smtp_sendmail_return = ""
try:
smtp_sendmail_return = server.sendmail(email_from, email_to, msg.as_string())
except Exception, e:
print 'SMTP Exception:\n' + str( e) + '\n' + str( smtp_sendmail_return)
finally:
server.quit()
评论列表
文章目录