Django: Setting the from address on an email

后端 未结 1 1066
孤街浪徒
孤街浪徒 2021-01-26 03:19

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-addr

相关标签:
1条回答
  • 2021-01-26 04:12

    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()
    
    0 讨论(0)
提交回复
热议问题