python-emails icon indicating copy to clipboard operation
python-emails copied to clipboard

Provide a convenient way to set Reply-To

Open vfaronov opened this issue 7 years ago • 2 comments

Currently, there’s no way to set Reply-To in the same way as To, Cc, or Bcc:

>>> import emails
>>> ivan = ('Иван', '[email protected]')
>>> maria = ('Марья', '[email protected]')
>>> msg = emails.Message(mail_to=[ivan], cc=[maria], text='Hello world!')
>>> print(msg.as_string())
[...]
To: =?utf-8?b?0JjQstCw0L0=?= <[email protected]>
Cc: =?utf-8?b?0JzQsNGA0YzRjw==?= <[email protected]>
[...]
>>> msg = emails.Message(mail_to=[ivan], reply_to=[maria], text='Hello world!')
Traceback (most recent call last):
  File "<ipython-input-13-598375a47f5d>", line 1, in <module>
    msg = emails.Message(mail_to=[ivan], reply_to=[maria], text='Hello world!')
TypeError: __init__() got an unexpected keyword argument 'reply_to'

>>> msg = emails.Message(mail_to=[ivan], headers={'Reply-To': [maria]}, text='Hello world!')
>>> print(msg.as_string())
[...]
Reply-To: ,
To: =?utf-8?b?0JjQstCw0L0=?= <[email protected]>
[...]

A reply_to parameter to emails.Message (and emails.html, etc.) would be nice.

vfaronov avatar Nov 14 '17 15:11 vfaronov

relates to #73

lavr avatar Dec 13 '17 13:12 lavr

This seems possible using the undocumented headers option:

In [10]: print(emails.Message(mail_to="[email protected]", text="hi", headers={"Reply-To": "[email protected]", "Return-Path": "[email protected]"}).as_string())
Content-Type: multipart/mixed; boundary="===============1059280084=="
MIME-Version: 1.0
Date: Mon, 18 Dec 2017 09:15:46 +0100
Reply-To: [email protected]
Return-Path: [email protected]
To: [email protected]

Not sure if this is the right way, but I think headers should really be documented, if it is.

silverwind avatar Dec 18 '17 08:12 silverwind