import smtplib
from email.mime.text import MIMEText
_user = "1147016115@qq.com"#發件人
_pwd = "wcpxldrtuthagjbc"#qq郵箱授權碼
_to = "1208832227@qq.com"#收件者
msg = MIMEText("Hellow,This is my first Email!")#郵件內容
msg["Subject"] = "come form xieolei! "#收件者顯示的郵件主題
msg["From"] = _user#收件者顯示的寄件者
msg["To"] = _to#收件者顯示的收件者
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(_user, _pwd)
s.sendmail(_user, _to, msg. as_string())
s.quit()
print ("Success!")
except smtplib.SMTPException.e:
##except smtplib.SMTPException.e:
# 執行結果:
#附:程式碼原始碼:###############
import smtplibfrom email.mime.text import MIMEText _user = "1147016165@qq.com"#发件人_pwd = "hhvzrkmhnrfgicee"#qq邮箱授权码_to = "1208832367@qq.com"#收件人msg = MIMEText("Hellow,This is my first Email!")#邮件内容msg["Subject"] = "come form xieolei!"#收件方显示的邮件主题msg["From"] = _user#收件方显示的发件人msg["To"] = _to#收件方显示的收件人try: s = smtplib.SMTP_SSL("smtp.qq.com", 465) s.login(_user, _pwd) s.sendmail(_user, _to, msg.as_string()) s.quit() print ("Success!")except smtplib.SMTPException.e: print ("Falied,%s"%e)
以上是Python郵件如何傳送?的詳細內容。更多資訊請關注PHP中文網其他相關文章!