Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python通过hotmail.com帐户自动发送电子邮件?_Python_Microsoft Graph Api - Fatal编程技术网

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

如何使用python通过hotmail.com帐户自动发送电子邮件?,python,microsoft-graph-api,Python,Microsoft Graph Api,因此,我一直在尝试使用@hotmail.com帐户以编程方式发送电子邮件 到目前为止,我成功地做到了: 在此处创建一个应用程序,并拥有: 应用程序ID “应用程序机密”下的密码 在plaftorms下,我添加了一个web和一个本机应用程序 在图形权限下,我在“Mail.Send”和“User.Read”下获得了委托权限 我已成功运行代码,通过浏览器发送电子邮件。 但是,我被要求作为身份验证过程的一部分登录 问题如下: 如何通过python发送电子邮件并使用@hotmail.com帐户,而无需

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

到目前为止,我成功地做到了:

  • 在此处创建一个应用程序,并拥有:
  • 应用程序ID
  • “应用程序机密”下的密码
  • 在plaftorms下,我添加了一个web和一个本机应用程序
  • 在图形权限下,我在“Mail.Send”和“User.Read”下获得了委托权限
  • 我已成功运行代码,通过浏览器发送电子邮件。
  • 但是,我被要求作为身份验证过程的一部分登录
  • 问题如下:

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

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


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

    乐意帮助:)
    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()