使用邮件第三方服务发送消息,当 smtp要求分别设定username和 sendermail 时,发信失败
{
“uniqueId”: “eafcf3e3-abc7-4eeb-92ea-55f906f62543”,
“code”: 422,
“statusCode”: 422,
“message”: “发送邮件失败: Mail command failed: 501 5.1.7 Invalid address”
}
该账号在以下脚本中可以正常完成发信
try:
print(“Connecting to the SMTP server…”)
使用SMTP服务器连接
with smtplib.SMTP(“mail.yuexiu-finance.com”, 587) as server:
print(“Connected to SMTP server. Starting TLS…”)
server.starttls() # 升级为加密连接
print(“TLS started. Logging in…”)
server.login(smtp_username, password)
print(“Logged in successfully. Sending email…”)
server.sendmail(sender_email, receiver_email, msg.as_string())
print(“Email sent successfully!”)
except smtplib.SMTPException as e:
print(f"Failed to send email. Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")