Django: Setting the from address on an email

ぃ、小莉子 提交于 2019-12-20 07:26:27

问题


I'd like for my users to be able to enter their email-address and message and then send the email with the 'from address' being their own email-address. Currently the EMAIL_HOST is set on our own domain and the emails arrives when it is sent with a "from address" equal to our HOST_USER, but not if it is anything else. Is this possible?

Our settings:

EMAIL_HOST = 'smtp02.hostnet.nl'  
EMAIL_PORT = 587  
EMAIL_USE_TLS = True  
EMAIL_HOST_USER = "xxx"  
EMAIL_HOST_PASSWORD = "xxx"  
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

回答1:


If you allow your users to set the from addresss, you may find that your emails are blocked by anti-spam measures.

A better approach would be to use an email address you control as the from address, and set the reply_to header on your email. Then, when the recipients click 'reply', the reply will go to the user's from address.

email = EmailMessage(
    'Hello',
    'Body goes here',
    'your-email-address@example.com',  # from address
    ['to1@example.com', 'to2@example.com'], # recipients
    reply_to=[user_from_address],  # reply to address set by your user
)
email.send()


来源:https://stackoverflow.com/questions/39660409/django-setting-the-from-address-on-an-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!