SMTP報錯 smtplib.SMTPDataError: 554, smtplib.SMTPAuthenticationError: 535 廖雪峰案例BUG
# -*- coding: utf-8 -*- """ Created on Thu Apr 26 19:57:32 2018 @author: yyhhlancelot """ import smtplib from email import encoders from email.header import Header from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase # 輸入Email地址和口令: #from_addr = input('From: ') sender = '
[email protected]' password = input('Password: ') # 輸入收件人地址: #to_addr = input('To: ') receiver = '[email protected]' # 輸入SMTP伺服器地址: #smtp_server = input('SMTP server: ') subject = 'test6' smtp_server = 'smtp.163.com' #郵件物件 msg = MIMEMultipart() msg.attach(MIMEText('<html><body><h1>Hello</h1>' + '<p>send by <a href="http://www.python.org">Python</a>...</p>' + '</body></html>', 'html', 'utf-8')) msg['Subject'] = Header(subject, 'utf-8') msg['From'] = '[email protected] <yyhhl[email protected]>' msg['To'] = 'yyhhlancelot <[email protected]>' #msg.attach(MIMEText('send with file...', 'plain', 'utf-8')) # 新增附件就是加上一個MIMEBase,從本地讀取一個圖片: with open('C:/Users/yyhhlancelot/Desktop/1.jpg', 'rb') as f: # 設定附件的MIME和檔名,這裡是png型別: mime = MIMEBase('image', 'jpeg', filename='1.jpg') # 加上必要的頭資訊: mime.add_header('Content-Disposition', 'attachment', filename='1.jpg') mime.add_header('Content-ID', '<0>') mime.add_header('X-Attachment-Id', '0') # 把附件的內容讀進來: mime.set_payload(f.read()) # 用Base64編碼: encoders.encode_base64(mime) # 新增到MIMEMultipart: msg.attach(mime) server = smtplib.SMTP(smtp_server, 25) # SMTP協議預設埠是25 server.set_debuglevel(1) server.login(sender, password) server.sendmail(sender, [receiver], msg.as_string()) server.quit()
上述程式碼是通過163郵箱傳送到qq郵箱。伺服器為163伺服器。
注意事項:
1.報錯535:
是因為未將POP3/SMTP服務開啟。此項通過在163郵箱內 設定 獲取授權碼 開啟,通過授權碼可以進行第三方登入。此處的Password填寫授權碼。
2.報錯554:
第一種情況:缺失發件人和主題,將msg['Subject'] msg['From'] msg['To'] 幾行新增。
第二種情況:網路的問題。當家裡的網路出現問題時,切換成手機熱點試試;當手機熱點出現問題時,切換成家裡的網路試試。這個問題真的把我弄得吐血。
相關推薦
SMTP報錯 smtplib.SMTPDataError: 554, smtplib.SMTPAuthenticationError: 535 廖雪峰案例BUG
# -*- coding: utf-8 -*- """ Created on Thu Apr 26 19:57:32 2018 @author: yyhhlancelot """ import smtplib from email import encoders from
【selenium+Python unittest】之發送郵箱時報錯:smtplib.SMTPDataError、smtplib.SMTPAuthenticationError(例:126郵箱)
pytho data 密碼 nec user 郵箱 ati width mtp 原代碼如下: import smtplib from email.mime.text import MIMEText from email.header import Header #要發送
smtplib.SMTPDataError: (554, b'DT:SPM 163 smtp10,DsCowAA3nir1u6xZq42WDw--.22935S2 1504492533,please
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.
smtplib.SMTPDataError: 554, 'DT:SPM
#coding: utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header sender = '[email protected]' rec
Python傳送郵件smtplib.SMTP各報錯問題的解決方法
經測試可用的傳送郵件程式碼: import smtplib from email.mime.text import MIMEText # 第三方 SMTP 服務 mail_host = "smtp.163.com" # SMTP伺服器 mail_user = "user
centOS+jenkins發送郵件報錯Unknown host name: smtp@163.com
socket response .com read apache stand abstract plugin ava Failed to send out e-mail java.net.UnknownHostException: [email protected] at java.
python SMTP傳送郵件/server.sendmail(from_addr, [to_addr], msg.as_string())報錯
? 1 2 3 4 5 6 7 8 9 importsmtplib server=smtplib.SMTP('smtp.163.com',25) server.login('[email
python通過SMTP協議傳送郵件失敗,報錯505或535
傳送失敗錯誤1:smtplib.SMTPAuthenticationError: (550, b'User has no permission') 我們使用python傳送郵件時相當於自定義客戶端
傳送自動郵件時Could not connect to SMTP host: 10.1.1.195, port: 25;報錯的解決方法
最近在測試公司內部系統自動傳送郵件功能時,一直在報錯: javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Coul
null值插入數據庫會報錯
point all color harmony 錯誤 ring amr red epo 2017-05-03 23:25:01,568 [com.creditharmony.adapter.dao.base.ParamRecordDao.insertException]-[
iWatch報錯: Missing com.apple.developer.healthkit entitlement
develop text app heal water fcm sdn zed center 今天開發iWatch項目,報錯: Optional (Error "Missing come.apple.developer.healthkit entitlement.")
Aptana Studion出現 duplicate location重復定位報錯
alt 出現 重新啟動 sar nis http ava 安裝 src 1、下載SVN的時候出現報錯 duplicate location 2、點擊“available software sites”查看已可用的軟件網站 3、在這裏可以查看到SVN,勾選SVN復選
【Netapp】在模擬器中使用disk removeowner報錯
disk removeowner報錯信息如下:Cluster2::storage disk*> removeowner NET-1.43 Error: command failed: Disk NET-1.43 is not conne
SQL Server導入報錯:The LocaleID 4 is not installed on this system
code page localeid 936 問題描述:通過SQLServer導入導出向導導入中文字符集數據,遇到The LocaleID 4 is not installed on this system.錯誤。解決方法:我發現客戶服務器操作系統雖然不支持Chinese (Simplified)
使用json報錯java.lang.NoClassDefFoundError: nu/xom/ParentNode
pid 方案 parent depend lan found group artifact cti 解決方案: 引入xom包; eg: <dependency> <groupId>xom</groupId> <artif
osx升級到10.10後,用pod install報錯終於解決的方法
... tar font tails http fat error: hat space 先依照這個文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概過程例如以下: Open Xcode 6O
webpack 打包壓縮 ES6文件報錯UglifyJs + Unexpected token punc «(», expected punc «:»
htm script 打包壓縮 scripts log res web save pla webpack打包壓縮 ES6 js react報錯: 升級到 babel6 了 ERROR in /Scripts/Test/test.bundle.js from UglifyJ
關於laravel連接數據庫報錯
mage config 緩存 有時 檢查 .com clear 連接數據庫 關於 今天第一次使用laravel框架連接數據庫,滿環激動,結果報連接數據失敗,反復檢查賬號密碼什麽都對,就是報連接失敗 php artisan config:clear 就是這個命令,清除了數
安裝mongodb後啟動報錯libstdc++
nbsp 下載 安裝mongodb 文件 lib64 png str rep 啟動 安裝mongo後啟動報錯如下圖 顯然說是libstdc++.so文件版本的問題,這種一般都是gcc版本太低了 接著查詢gcc的版本 strings /usr/lib/libstd
linux下weblogic11g成功安裝後,啟動報錯Getting boot identity from user
tro ace author reason tac ica ons pst pri <2015-7-1 下午05時46分33秒 CST> <Info> <Management> <BEA-141107> <Versi