首页 > 编程语言 > 详细

Python 发送邮件

时间:2021-07-19 22:58:29      阅读:23      评论:0      收藏:0      [点我收藏+]
import smtplib, ssl

smtp_server = "smtp.qq.com"
#port = 587  # For starttls [465端口不能发送]
port = 25  # For starttls
sender_email = "xxx@qq.com"
# password = input("Type your password and press enter: ")
password = "ixxzxfdgha"

# Create a secure SSL context
context = ssl.create_default_context()
message = """
Subject: Hi there

This message is sent from Python."""

to_email = "yyy@qq.com"
# Try to log in to server and send email
try:
    server = smtplib.SMTP(smtp_server, port)
    server.ehlo()  # Can be omitted
    server.starttls(context=context)  # Secure the connection
    server.ehlo()  # Can be omitted
    server.login(sender_email, password)
    # TODO: Send email here
    server.sendmail(sender_email, to_email, message)
    print("done")


except Exception as e:
    # Print any error messages to stdout
    print(e)
finally:
    server.quit()

Python 发送邮件

原文:https://www.cnblogs.com/lanqie/p/15032504.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!