smtplib.SMTPDataError: (554, b'DT:SPM 163 smtp10,DsCowAA3nir1u6xZq42WDw--.22935S2 1504492533,please

 1 # from email.mime.text import MIMEText
 2 #
 3 # msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')
 4 # # 输入Email地址和口令:
 5 # from_addr = input('From: ')
 6 # password = input('Password: ')
 7 # # 输入SMTP服务器地址:
 8 # smtp_server = input('SMTP server: ')
 9 # # 输入收件人地址:
10 # to_addr = input('To: ')
11 #
12 # import smtplib
13 #
14 # server = smtplib.SMTP(smtp_server, 25)  # SMTP协议默认端口是25
15 # server.set_debuglevel(1)
16 # server.login(from_addr, password)
17 # server.sendmail(from_addr, [to_addr], msg.as_string())
18 # server.quit()
19 
20 
21 
22 
23 # coding: utf-8
24 import smtplib
25 from email.mime.text import MIMEText
26 from email.header import Header
27 
28 sender = 'fengyiru6369@163.com'
29 receiver = '1194150169@qq.com'
30 subject = 'python email test'
31 smtpserver = 'smtp.163.com'
32 username = 'fengyiru6369@163.com'
33 password = 'XXXXXXXX'  # 是授权密码,而不是登录密码
34 
35 msg = MIMEText('你好', 'text', 'utf-8')  # 中文需参数‘utf-8’,单字节字符不需要
36 msg['Subject'] = Header(subject, 'utf-8')
37 
38 smtp = smtplib.SMTP()
39 smtp.connect('smtp.163.com')
40 smtp.login(username, password)
41 smtp.sendmail(sender, receiver, msg.as_string())
42 smtp.quit()

只赋值了msg['Subject'], 没有赋值msg['From'], msg['To'],导致出现554情况,更改了后就好了。

注意MIMEText初始化的时候,中文的第二个参数要用'plain',我用'text',中文就显示不出来。

msg['From'] 中人名为Tim,会和下面对应起来。

 

posted @ 2017-09-04 11:12  木棉花的漂泊  阅读(3742)  评论(0编辑  收藏  举报