使用qq的郵件服務器需要注意的兩個地方主要是:
1.協議問題 使用465端口 SSL 協議
2.口令問題 出現SMTPAuthenticationError 主要的原因就是口令和帳號信息不對,這里我們使用qq服務器發送 需要先到郵箱里設置獨立密碼(必須), 然后開啟
SMTP/POP3服務。然后用qq手機安全中心掃一掃會給一個授權碼, 在代碼中要填寫的密碼是這個授權碼, 而不是郵箱密碼!
下面貼個代碼:
#coding:utf8 from smtplib import SMTP_SSL from email.header import Header from email.mime.text import MIMEText mail_info = { "from": "xxxx@qq.com", "to": "xxx@qq.com", "hostname": "smtp.qq.com", "username": "xxx@qq.com", "password": "xxx", "mail_subject": "test", "mail_text": "hello, this is a test email, sended by py", "mail_encoding": "utf-8" } if __name__ == '__main__': #這里使用SMTP_SSL就是默認使用465端口 smtp = SMTP_SSL(mail_info["hostname"]) smtp.set_debuglevel(1)
smtp.ehlo(mail_info["hostname"]) smtp.login(mail_info["username"], mail_info["password"]) msg = MIMEText(mail_info["mail_text"], "plain", mail_info["mail_encoding"]) msg["Subject"] = Header(mail_info["mail_subject"], mail_info["mail_encoding"]) msg["from"] = mail_info["from"] msg["to"] = mail_info["to"]
smtp.sendmail(mail_info["from"], mail_info["to"], msg.as_string()) smtp.quit()
Debian系 os 截圖命令 gnome-screenshot -a 自定義區域截圖后的文件放在 HOME 目錄下的Picture文件夾里。