1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/env python #_*_ coding: utf-8 _*_ import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = 'xxxxxxx@xxxxxx.com' #发件人
receiver = [ 'xxxxxxx@qq.com' ] #收件人
subject = 'python email test' #定义主题
smtpserver = 'mail.urundp.com' #第三方smtp服务器
username = 'xxxxx@xxxxxx.com' #用户名
password = 'xxxxxxxx' #密码
msg = MIMEText( 'Python mail test' , 'plain' , 'utf-8' ) #格式:邮件内容/格式/编码
msg[ 'Subject' ] = Header(subject, 'utf-8' )
try :
smtp = smtplib.SMTP()
smtp.connect( 'mail.urundp.com' )
smtp.ehlo()
smtp.starttls()
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print '邮件发送成功'
except smtplib.SMTPException,ex:
print '邮件发送失败' ,ex
|
本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/1873628