Send Email by Python
Send Email by Python
使用Python发送邮件Key_points:SMTP服务器地址和端口使用TLS加密: 587代码语言:javascript代码运行次数:0运行复制server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()使用SSL加密: 465代码语言:javascript代码运行次数:0运行复制ser
Send Email by Python
使用Python发送邮件
Key_points:
SMTP服务器地址和端口
使用TLS加密: 587
代码语言:javascript代码运行次数:0运行复制server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
使用SSL加密: 465
代码语言:javascript代码运行次数:0运行复制server = smtplib.SMTP_SSL(smtp_server, smtp_port)
代码如下:
代码语言:javascript代码运行次数:0运行复制import smtplib
from import MIMEText
from import MIMEMultipart
# 发送邮件
def send_email():
print("Preparing to send email...")
sender_email = 'your_email@example'
receiver_email = 'receiver_email@example'
password = 'your_email_password'
smtp_server = 'smtp.yourmail'
smtp_port = 587 # SMTP端口, 通常为587(TSL)或465(SSL)
subject = 'subject'
body = 'body'
message = MIMEMultipart()
message['From'] = sender_email
message['To'] = receiver_email
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))
try:
print("Connecting to SMTP server...")
# If you want to use SSL, use `smtplib.SMTP_SSL()` instead and remove `server.starttls()`
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls() # 使用TLS加密
print("Logging in to SMTP server...")
server.login(sender_email, password) # 登录
print("Sending email...")
server.sendmail(sender_email, receiver_email, message.as_string()) # 发送邮件
print("Email sent successfully.")
except Exception as e:
print(f"Email sent failed: {e}")
# 主函数
def main():
send_mail()
文章作者: Alan Zeng
原始链接: /
版权说明:本博客所有文章除特别声明外,均采用BY-C-SA 4.0许可协议。获得许可后,要求转载时注明文章出处和网站链接,谢谢!
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-09-09,如有侵权请联系 cloudcommunity@tencent 删除server加密pythonemailsend#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上传时间: 2025-07-21 20:48:30
推荐阅读
留言与评论(共有 18 条评论) |
本站网友 华晋焦煤 | 11分钟前 发表 |
print(f"Email sent failed | |
本站网友 ulysses | 5分钟前 发表 |
{e}") # 主函数 def main() | |
本站网友 双重人格测试 | 16分钟前 发表 |
message.as_string()) # 发送邮件 print("Email sent successfully.") except Exception as e | |
本站网友 梅新育 | 20分钟前 发表 |
SMTP服务器地址和端口使用TLS加密 | |
本站网友 斜视治疗 | 11分钟前 发表 |
要求转载时注明文章出处和网站链接 | |
本站网友 ogame | 26分钟前 发表 |
{e}") # 主函数 def main() | |
本站网友 禁娱令 | 7分钟前 发表 |
谢谢! 本文参与 腾讯云自媒体同步曝光计划 | |
本站网友 北京东方医院怎么样 | 26分钟前 发表 |
分享自作者个人站点/博客 | |
本站网友 guosen | 1秒前 发表 |
'plain')) try | |
本站网友 手机序列号 | 26分钟前 发表 |
均采用BY-C-SA 4.0许可协议 | |
本站网友 苏田田 | 25分钟前 发表 |
{e}") # 主函数 def main() | |
本站网友 重庆房子 | 23分钟前 发表 |
print("Preparing to send email...") sender_email = 'your_email@example' receiver_email = 'receiver_email@example' password = 'your_email_password' smtp_server = 'smtp.yourmail' smtp_port = 587 # SMTP端口 | |
本站网友 潼关二手房 | 16分钟前 发表 |
分享自作者个人站点/博客 | |
本站网友 萌芽电影 | 21分钟前 发表 |
print(f"Email sent failed | |
本站网友 大连幼儿园 | 13分钟前 发表 |
smtp_port) as server | |
本站网友 铁皮枫斗功效 | 22分钟前 发表 |
如有侵权请联系 cloudcommunity@tencent 删除前往查看server加密pythonemailsend | |
本站网友 jap | 4分钟前 发表 |
分享自作者个人站点/博客 |