Emails, a different 'reply to' address than sender address
Asked Answered
P

4

14

I have a contact form on a website (a general form: name, email, subject, message) in which mails are sent using google apps smtp to the admins.
Currently if an administrator wants to reply to the mail directly selecting the reply option, the person's reply's To field will be filled by the sender's address automatically.

What I wan't to ask is, Is there any standardized way to pass on some additional info with the mail which would define any reply to the mail should go to this address instead of the sender's?

It does seems that there is a little chance for this option as it may lead to some problems due to spammers (They may define a custom reply field in their mail and a general user might not look where they are replying).

So as an alternative what I thought is to find a way to create a filter with sender's account which figures out the reply email address from the format and forwards the mail (Doesn't seems like a good solution and I have no idea how to achieve this).

I have tagged django, though this is not directly related with this, as I will finally implement this through django.

Pigpen answered 5/1, 2011 at 4:41 Comment(0)
P
15

There are in fact standardized headers to specify response headers: http://cr.yp.to/immhf/response.html.

As far as implementing this in Django is concerned, the documentation contains an example:

from django.core.mail import EmailMessage

email = EmailMessage(
    'Hello', # email subject
    'Body goes here', # email body
    '[email protected]', # sender address
    ['[email protected]', '[email protected]'],
    ['[email protected]'],
    headers={'Reply-To': '[email protected]'},
)

This solved my problem.

Pigpen answered 5/1, 2011 at 4:54 Comment(1)
Note that in Django 1.8, a new reply_to parameter has been added to the EmailMessage object.Sesqui
L
4

Reply-To is a standard SMTP header.

I can't find a good reference for it at the moment, but it is mentioned in the Wikipedia article on Email.

Edit: Found it: RFC 5322, section 3.6.2

Llano answered 5/1, 2011 at 4:49 Comment(2)
thanks @david, Found the reply to specs in the appendix A.2; Can't this be a little dangerous if spammers spoof the reply to email address?Pigpen
No more than spoofing the from address, which they are already doing. But to the best of my knowledge, most spam is an advertisement, not intended to be replied to, so I don't think the Reply-To address matters much.Llano
C
2

The RFC says you can specify multiple emails and that is what I was looking for. Came up with this:

from django.core.mail import EmailMessage
headers = {'Reply-To': '[email protected];[email protected]'}
msg = EmailMessage(subject, html_content, EMAIL_HOST_USER, email_list, headers=headers)
msg.content_subtype = "html"
msg.send()

Works like a charm. Note: EMAIL_HOST_USER is imported from your settings file as per Django doc email setup. More on this here, search for 'reply-to': https://docs.djangoproject.com/en/dev/topics/email/

Constituency answered 28/2, 2014 at 18:4 Comment(0)
M
0

Here is also how reply-to can be used

from django.core.mail import EmailMessage

email = EmailMessage(
    'Hello',
    'Body goes here',
    '[email protected]',
    ['[email protected]', '[email protected]'],
    ['[email protected]'],
    reply_to=['[email protected]'],
    headers={'Message-ID': 'foo'},
)

Read more at docs docs.djangoproject

Mekong answered 17/1, 2019 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.