Java mail returned email address

I need to send messages to many clients. But many of them recovered. I want a list of these email addresses. How can I get this list from my Java application?

+4
source share
2 answers

Create a special email address bounced@yourdomain.com , where you will display all bounced emails for analysis.

Add the following sent messages:

Return-Path: < bounced@yourdomain.com > 

Letters will now return to this address.

From time to time, read letters to this address from your Java program, for example, through IMAP (or depending on your server through the notification interface / independently), and when you see the email address, write it to your database

Please note that if you are creating a newsletter application, you should not blacklist the e-mail the first time, but force it to be counted, and the black one after 3-4 bounces (some people set their e-mail to bounce when they go on vacation etc., so they need special care).

+3
source

I solve this issue using

 SMTPMessage msg = new SMTPMessage(getSession()); msg.setEnvelopeFrom(bounceAddr); 

See the javamail document and see it:

 void com.sun.mail.smtp.SMTPMessage.setEnvelopeFrom(String from) 

Set the From address to display in the SMTP envelope. Note that this is different from the From address that appears in the message itself. An envelope from address is usually used when sending error messages. See RFC 821 for details.

If set, overrides the mail.smtp.from property.

Parameters: from envelope From address

+1
source

Source: https://habr.com/ru/post/1385728/


All Articles