【问题标题】:How to send Email in Django using office365如何使用 office365 在 Django 中发送电子邮件
【发布时间】:2021-03-31 09:21:57
【问题描述】:

我正在一个项目中工作,我需要将电子邮件发送给在表单中填写电子邮件的用户。我可以使用我的Gmail Account 详细信息发送电子邮件,但同时使用outlook.365This is the image with error that I am getting.

我的要求是:

  1. 一旦用户进入注册表并填写详细信息,如姓名、电子邮件、手机
  2. 无论在表单中输入什么电子邮件,发送带有链接的电子邮件以创建新密码。

这是我的代码:

settings.py:

 # Using outlook365:

 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
 EMAIL_HOST_USER = 'support@academic.com'
 EMAIL_HOST = 'smtp.outlook.office365.com'  # (also tried : smtp.office365.com  and  
 outlook.office365.com)

 EMAIL_PORT = 587
 EMAIL_USE_TLS = True
 EMAIL_HOST_PASSWORD = 'My_Password'


 # Using my gmail account:

 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
 EMAIL_HOST_USER = 'admin@gmail.com'
 EMAIL_HOST = 'smtp.gmail.com'
 EMAIL_PORT = 587
 EMAIL_USE_TLS = True
 EMAIL_HOST_PASSWORD = 'My_Password'

views.py:

 subject = "Academic - Create New Password"
 message = "Hi %s! Please create your new Password here : http://127.0.0.1:8000/api/create-password"  % firstname

 send_mail(
        subject,  # Subject of the email
        message,  # Body or Message of the email
        'support@academic.com',  # from@gmail.com   (admin@gmail.com for gmail account)
        [email],  # to@gmail.com  # email that is filled in the form
    )

请指导我使用 Outlook365 发送电子邮件需要哪些额外设置或配置。

【问题讨论】:

    标签: python django django-rest-framework outlook rest


    【解决方案1】:

    请将其放入 settings.py 文件中。

    SERVER_EMAIL = EMAIL_HOST_USER
    

    【讨论】:

    • 我遇到了同样的错误。和你说的一样吗:EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_HOST_USER = 'support@academic.com'SERVER_EMAIL = EMAIL_HOST_USEREMAIL_HOST = 'smtp.outlook.office365.com'EMAIL_PORT = 587EMAIL_USE_TLS = TrueEMAIL_HOST_PASSWORD = 'My_Password'
    【解决方案2】:

    您的设置看起来正确。使用EMAIL_HOST = "smtp.office365.com"。验证您使用的凭据是否正确。检查您的 Outlook 帐户是否设置正确,可以从support@academic.com 发送电子邮件。

    【讨论】:

      猜你喜欢
      • 2020-04-26
      • 2020-02-06
      • 2017-10-12
      • 2021-09-28
      • 2021-02-24
      • 2019-07-23
      • 2020-05-03
      • 2018-07-24
      • 2018-02-20
      相关资源
      最近更新 更多