pythonmailer和google有问题吗?

2024-10-02 12:24:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚试过以下方法:

server = smtplib.SMTP(smtpname, smtpport)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(username, recipient, "TEST")
server.close()

smtpname是“smtp.gmail.com“,smtport是587,用户名是google acc+”@gmail.com网站,收件人是第二个gmail。在

谁能告诉我怎么了?脚本在python中运行,没有错误,但是我什么也没有得到


Tags: 方法comserverusernameloginpasswordsmtpgmail
1条回答
网友
1楼 · 发布于 2024-10-02 12:24:18

看看email example

“TEST”字符串的使用应该是格式正确的MIME消息。在

在您的情况下,应该是: 从电子邮件.mime.text导入MIMEText

import smtplib

# Create a MIME text message and populate its values
msg = MIMEText("TEST")
msg['Subject'] = "TEST"
msg['From'] = username
msg['To'] = recipient

server = smtplib.SMTP(smtpname, smtpport)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)

# Send a properly formatted MIME message, rather than a raw string
server.sendmail(username, recipient, msg.as_string())
server.close()

相关问题 更多 >

    热门问题