[Fixed]-Django: Setting the from address on an email

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()

Leave a comment