Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change _MailMixin.send signature and procedure #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pbu88
Copy link

@pbu88 pbu88 commented Jun 16, 2014

  1. Add the parameter envelope_from=None to be able to modify the envelope from
    from client code. The former version had envelope_from parameter only in
    Connection.send and it was impossible to call from client code without hacking
    a little.

  2. In order to use this parameter, the mail is sent using the connection
    object instead of the message object. This also reduce one level of innecesary
    indirection (Message.send only does connection.send(self))

1) Add the parameter `envelope_from=None` to be able to modify the envelope from
from client code. The former version had `envelope_from` parameter only in
`Connection.send` and it was impossible to call from client code without hacking
a little.

2) In order to use this parameter, the mail is sent using the `connection`
object instead of the `message` object. This also reduce one level of innecesary
indirection (`Message.send` only does `connection.send(self)`)
@pbu88
Copy link
Author

pbu88 commented Jun 16, 2014

There was no simple way to call Connection.send with envelope_form parameter. Normal client code should go like this (as stated in the docs)

msg = Message(...)
mail.send(msg) #nowhere to set seamlessly the envelope_from argument

@jamesonjlee
Copy link
Collaborator

is this actually the need to differentiate between Sender and From?

@pbu88
Copy link
Author

pbu88 commented Aug 6, 2014

The need arose when we wanted to redirect bounce emails to another account. Say [email protected] sends an email to a client, but that client's email not longer exists, so the server will return a bounce email saying that the mail was not found. That mail is normally sent to the "envelope-form" field which is almost always the same as the sender. In our case, we wanted to track this in another mail account so there's the motivation to the pull request.

@jamesonjlee
Copy link
Collaborator

that sounds exactly like the scenario for differentiating From the author of the message, to the Sender the agent who will deliver the authored message (and therefor should not receive the actual replies).

e.g. here:
http://tools.ietf.org/html/rfc5322#section-3.6.2

@pbu88
Copy link
Author

pbu88 commented Sep 29, 2014

Hi, any feedbacks on this? Can I help somehow? This is a very simple change but I will be glad to provide some tests if needed or help in something.

@jamesonjlee
Copy link
Collaborator

@pbu88 I'm open to exposing this better from the Message class rather than by send(). Have you tried using mail_options to achieve this goal?

@pbu88
Copy link
Author

pbu88 commented Oct 2, 2014

We could add an envelope_from field to the Message class and have Connection.send method (https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L188) do this instead:

self.host.sendmail(sanitize_address(message.envelope_from or message.sender)

This will deprecate the need for an envelope_from optional argument in that method. Unfortunately, I don't see a way of doing this without actually modifying the current code. Envelope from is the first argument to SMTP's FORM command and is also the first argument of SMTP.sendmail() method. It makes sense to me to have it on the Message object too, but I took this path because I already saw it as an optional argument on Connection.send() method.

The actual use case for this is not only hiding the originator mail (or changing it). It's main purpose is control the bounce when the mail failed to deliver. I'll love to hear some feedback about this :)

@pbu88
Copy link
Author

pbu88 commented Oct 3, 2014

Actually, I'm not that comfortable with including envelope_from in Message object. In my opinion Message objects represent the content passed to the SMTP's DATA command. Envelope from is argument of SMTP's MAIL command, they are somehow independent from each other. Since, I think, the Mail object plays a nice role abstracting the SMTP conversation between the client and the server, the envelope from argument should be handled in Mail object (_MailMixin in this case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants