gpt4 book ai didi

Python:电子邮件问题

转载 作者:太空狗 更新时间:2023-10-30 02:14:11 24 4
gpt4 key购买 nike

我正在使用下面的脚本向自己发送电子邮件,该脚本运行良好且没有错误,但我没有实际收到电子邮件。

import smtplib

sender = 'foo@hotmail.com'
receivers = ['foo@hotmail.com']

message = """From: From Person <foo@hotmail.com>
To: To Person <foo@hotmail.com>
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"

编辑

脚本名为test.py

最佳答案

为什么使用 localhost 作为 SMTP?

如果您使用的是hotmail,您需要使用hotmail账号,提供密码,输入端口和SMTP服务器等。

这里有你需要的一切: http://techblissonline.com/hotmail-pop3-and-smtp-settings/

编辑:以下是您使用 gmail 的示例:

def mail(to, subject, text):
msg = MIMEMultipart()

msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject

msg.attach(MIMEText(text))

part = MIMEBase('application', 'octet-stream')
Encoders.encode_base64(part)
msg.attach(part)

mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()

关于Python:电子邮件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3346996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com