import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
SMTP_HOST = "smtp.example.com"
SMTP_PORT = 587
SMTP_USERNAME = "your_username"
SMTP_PASSWORD = "your_password"
SMTP_STARTTLS = True
sender = "sender@example.com"
recipient = "recipient@example.com"
subject = "Test Email"
message = "This is a test email."
msg = MIMEMultipart()
msg["From"] = sender
msg["To"] = recipient
msg["Subject"] = subject
msg.attach(MIMEText(message))
smtp = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
smtp.ehlo()
if SMTP_STARTTLS:
smtp.starttls()
smtp.ehlo()
if SMTP_USERNAME and SMTP_USERNAME:
smtp.login(SMTP_USERNAME, SMTP_PASSWORD)
smtp.sendmail(sender, recipient, msg.as_string())
smtp.quit()
TOC
Python SMTP
发布于码厩技术博客的所有文章,除注明转载外,均为作者原创,欢迎转载,但必须注明出处。
尊重他人劳动,共创开源社区!转载请注明以下信息:
转载来源: 码厩技术博客 [https://www.markjour.com]
原文标题:Python SMTP
原文地址:/article/20180413-python-smtp.html
尊重他人劳动,共创开源社区!转载请注明以下信息:
转载来源: 码厩技术博客 [https://www.markjour.com]
原文标题:Python SMTP
原文地址:/article/20180413-python-smtp.html
