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

Add support for the mail envelope from #102

Closed
amanteaux opened this issue Oct 2, 2017 · 8 comments
Closed

Add support for the mail envelope from #102

amanteaux opened this issue Oct 2, 2017 · 8 comments

Comments

@amanteaux
Copy link
Contributor

To handle bounced emails with a dedicated email address, it is required to set the envelope from mail address: https://stackoverflow.com/questions/1782659/how-to-set-the-return-path-to-an-email-address-other-than-sender-address-using-j

Currently Simple Java Mail enables to set the SMTP parameter mail.smtp.from via the configuration of the Session of the Mailer.

It would be great if Simple Java Mail could:

  • handle a property to manage the mail.smtp.from option directly (so users won't have to deal with the Session object),
  • handle the "envelope from" property per mail (if the solution with SMTPMessage in the stackoverflow issue works: I have not tested it yet).

If that's ok, I can help implementing these features (and also test the solution with SMTPMessage).

@bbottema
Copy link
Owner

bbottema commented Oct 2, 2017

Isn't this the replyTo you are referring to?

@amanteaux
Copy link
Contributor Author

Actually the replyTo enables to set an address that will be used when the recipient will answer the mail.
Whereas in the case of the mail envelope from field, the address will be used by MTA and SMTP servers to notify the sender that the email could not be sent.

Usually the default behavior is correct: we want the sender to be directly notified when an email could not be sent.
However, in some cases we want to be able to customize the address that will be used in the Return-Path header (that will be set by the SMTP server). In my current case, I want to use the Return-Path field for technical reasons: my client wants to use a special address for sending mails, but he cannot see the received emails in this address (big corporation, slow processes...) and he also wants to be notified when emails could not be sent.
But I think other people can benefit from this feature: you may want to have a nice email address to send mails and use a dedicated address like bounced@domain.com to automatically handle bounced back emails by a reporting software.

@bbottema
Copy link
Owner

bbottema commented Oct 6, 2017

It's also written that the from address should be filled by the receiving party, not the sending party. I'm still looking into it, but it's a little confusing.

@amanteaux
Copy link
Contributor Author

It seems that this is the Return-Path header field that is filled by the receiving party.

However this field should be based on the mail envelope from value that is sent to the mail server before the mail object.

Currently I made some tests with Google accounts and non existing email providers: each time the SMTP server I am connecting to (a postfix server on my network, not the Google mail server) is notifying me on the correct address (not the one I sent the e-mail from).
Also the tests were currently only made with the mail.smtp.from parameter in the Session class.

@bbottema
Copy link
Owner

bbottema commented Oct 7, 2017

Excellent, I'll add it in this weekend. Thanks for the tests!

@amanteaux
Copy link
Contributor Author

Thank you for your help!

If you want, I can also make a test with the SMTPMessage solution to set the mail envelope from value. This other solution would enable to use this feature per Mail instead of using it per Mailer.

@bbottema bbottema added this to the 4.5.0 milestone Oct 21, 2017
@bbottema
Copy link
Owner

bbottema commented Nov 1, 2017

Currently working on these changes. Going to name it bounceToRecipient

email.setBounceToRecipient(..)
emailBuilder.bounceTo(..)

The JavaDoc will explain it will optionally set the Return-Path / Envelope FROM as a hint for the SMTP server to return bouncing emails to...

bbottema added a commit that referenced this issue Nov 3, 2017
@bbottema bbottema closed this as completed Nov 3, 2017
@amanteaux
Copy link
Contributor Author

That sounds perfect, thank you!!

bbottema added a commit that referenced this issue Nov 12, 2017
#102: When parsing MimeMessage to Email, also include the Return-Path as bounceToAddress
#95: When parsing MimeMessage to Email, also include the Return-Receipt-To
#93: When parsing MimeMessage to Email, also include the Disposition-Notification-To
Other: Overhauled MimeMessageParser to be more useful and usable (including better exceptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants