gpt4 book ai didi

python - 如何使用 python 通过我的 hotmail.com 帐户自动发送电子邮件?

转载 作者:行者123 更新时间:2023-12-01 08:53:55 25 4
gpt4 key购买 nike

因此,我一直在尝试使用我的 @hotmail.com 帐户以编程方式发送电子邮件。

到目前为止我已经成功做到了:

  1. 在此处创建应用程序 https://apps.dev.microsoft.com/#/appList并有:
    1. 应用程序 ID
    2. “应用程序 secret ”下的密码
    3. 在平台下,我添加了一个网络和一个 native 应用程序
    4. 在图表权限下,我拥有委派权限“Mail.Send”和“User.Read”
  2. 我已成功运行 this通过浏览器发送电子邮件的代码。
    1. 但是,作为身份验证过程的一部分,我被要求登录。

问题如下:

如何通过 python 并使用我的 @hotmail.com 帐户发送电子邮件,而无需每次都提供任何登录凭据?

理想的解决方案是一个简单的 sendmail(to, subject, body) (或类似的)和一个带有应用程序特定密码的配置文件(我想我已经有了)。

最初,我希望查看上面链接中的示例 python 代码(重复 here )并尝试对其进行调整,但这不是正确的方法,因为示例代码需要通过浏览器登录。

最佳答案

from email import encoders
from email.message import Message
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def SendEmail():
s = smtplib.SMTP('smtp.gmail.com', 587) #Change smtp for Outlook
s.starttls()
s.login(EmailGoesHere, PASSWORDHere)

msg = MIMEMultipart() # create a message

# add in the actual person name to the message template
message = '''
Message Goes here
'''

# Prints out the message body for our sake
# print(message)

# setup the parameters of the message
msg['From']=MY_ADDRESS
msg['To']='ecesisproduction@gmail.com'
msg['Subject']="Marketplace order Accepted!"

# add in the message body
msg.attach(MIMEText(message, 'plain'))

# send the message via the server set up earlier.
s.send_message(msg)

# Terminate the SMTP session and close the connection
s.quit()

关于python - 如何使用 python 通过我的 hotmail.com 帐户自动发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52907945/

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