真实莫名其妙了,同一台主机,我的代码就不行,发了ehlo后就主动断了。
代码网上百度的,有啥问题,我在windows下也没问题。
import smtplib
from email.mime.text import MIMEText
from email.Header import Header
#import requests
import json
import time
mail_host = "" # 设置qq服务器
mail_user = "" # 用户名
mail_pass = "" # 密码
sender = '' # 发件人邮箱
receivers = ['] # 收件人邮箱,可设置为你的QQ邮箱或者其他邮箱
if __name__ == '__main__':
mail_content = "Testing..." # 邮件内容
message = MIMEText(mail_content, 'plain', 'utf-8')
message['Subject'] = Header('python', 'utf-8') # 邮件主题
message['From'] = Header("sender", 'utf-8') # 发件人昵称
message['To'] = Header("receivers", 'utf-8') # 收件人昵称
try:
smtp = smtplib.SMTP(mail_host,25) # SMTP_SSL默认使用465端口
smtp.set_debuglevel(2)
# smtp.ehlo("abcdefg")
smtp.login(mail_user, mail_pass)
smtp.sendmail(sender, receivers, message.as_string()) # 发送邮件
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error: 无法发送邮件")
print('邮件发送失败:', e)
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved