内容目录
原因
公司打印机需要扫描后发送邮件功能,但是公司用的sendgrid服务来发送邮件,密码长度69位太长,C3320最长只能32位,只能使用其他smtp.
刚开始使用个人QQ邮箱来smtp发信,后面为了正规一点使用腾讯企业邮箱来发送邮件
python测试脚本
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# 填写以下变量
SMTP_SERVER = "smtp.qq.com"
SMTP_PORT = 465
SENDER_EMAIL = "xxxxx@qq.com" # 你的Outlook邮箱地址
SENDER_PASSWORD = "sd5s5dsd5as5" # 你的授权码 应用密码
RECIPIENT_EMAIL = "xxxxx@outlook.com" # 收件人邮箱
SUBJECT = "Test Email"
BODY = "This is a test email sent using SMTP with an app password."
# 创建邮件内容
msg = MIMEMultipart()
msg['From'] = SENDER_EMAIL
msg['To'] = RECIPIENT_EMAIL
msg['Subject'] = SUBJECT
msg.attach(MIMEText(BODY, 'plain'))
# 使用SMTP协议发送邮件
try:
# 连接到Outlook的SMTP服务器
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
server.starttls() # 启用TLS加密
server.login(SENDER_EMAIL, SENDER_PASSWORD) # 使用邮箱和应用密码登录
server.sendmail(SENDER_EMAIL, RECIPIENT_EMAIL, msg.as_string()) # 发送邮件
print("邮件发送成功")
except Exception as e:
print(f"邮件发送失败: {e}")
finally:
server.quit() # 退出SMTP连接
1.个人QQ邮箱设置
设置>账号
授权码获取
如果已经打开imap pop stmp服务点击生成授权码就行,授权码就是密码
如果公司为了数据安全,请不要勾选SMTP发送保存到服务器
官方教程:https://wx.mail.qq.com/list/readtemplate?name=app_intro.html#/agreement/authorizationCode
2.腾讯企业邮箱设置
域名解析
cloudflare示例
两个mx 三个cname
官方教程:https://open.work.weixin.qq.com/help2/pc/19888?person_id=1
DKIM
为了防止收件人出现这个提示,需要添加DKIM txt解析
企业微信管理页面>>协作>>邮件>>安全设置
cloudflare或者其他DNS服务添加txt解析
添加邮箱
授权码生成
官方教程:https://open.work.weixin.qq.com/help2/pc/19886?person_id=1
然后填写即可使用
近期评论