smtplib.SMTPDataError: (554, b'DT:SPM 163 smtp10,DsCowAA3nir1u6xZq42WDw--.22935S2 1504492533,please
阿新 • • 發佈:2017-09-04
utf-8 sco put .com 收件人 input lai username p s
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 importMIMEText 26 from email.header import Header 27 28 sender = ‘[email protected]‘ 29 receiver = ‘[email protected]‘ 30 subject = ‘python email test‘ 31 smtpserver = ‘smtp.163.com‘ 32 username = ‘[email protected]‘ 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,會和下面對應起來。
smtplib.SMTPDataError: (554, b'DT:SPM 163 smtp10,DsCowAA3nir1u6xZq42WDw--.22935S2 1504492533,please