lavr / python-emails

Modern python library for emails
http://python-emails.readthedocs.org
Other
400 stars 54 forks source link

Provide a convenient way to set Reply-To #115

Open vfaronov opened 6 years ago

vfaronov commented 6 years ago

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

>>> import emails
>>> ivan = ('Иван', 'ivan@example.com')
>>> maria = ('Марья', 'maria@example.net')
>>> msg = emails.Message(mail_to=[ivan], cc=[maria], text='Hello world!')
>>> print(msg.as_string())
[...]
To: =?utf-8?b?0JjQstCw0L0=?= <ivan@example.com>
Cc: =?utf-8?b?0JzQsNGA0YzRjw==?= <maria@example.net>
[...]
>>> 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=?= <ivan@example.com>
[...]

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

lavr commented 6 years ago

relates to #73

silverwind commented 6 years ago

This seems possible using the undocumented headers option:

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

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