Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting 'message successfully delivered' to the wrong mail address in Java Mail API
    primarykey
    data
    text
    <p>I have started implementing a mailing module using the JAVA mail API. Am using the SMTPMessage, so that i can get the delivery status of the mail. Problem is am getting successful delivery report for <code>wrong mail addresses</code></p> <p>This is what i have done to send the message</p> <pre><code>SMTPMessage smtpMsg=new SMTPMessage(message); smtpMsg.setReturnOption(SMTPMessage.RETURN_HDRS); smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS |SMTPMessage.NOTIFY_FAILURE); Transport transport = session.getTransport("smtp"); //attach the listeners for the connection and transmission transport.addConnectionListener(this); transport.addTransportListener(this); transport.connect(); //connect to the server and send the message transport.sendMessage(smtpMsg, smtpMsg.getAllRecipients()); </code></pre> <p>Since my class implements <code>TransportListener,ConnectionListener</code>, i have attached listeners as</p> <pre><code>public void opened(ConnectionEvent e) { System.out.println("Connection opened"); } public void disconnected(ConnectionEvent e) { System.out.println("Connection disconnected"); } public void closed(ConnectionEvent e) { System.out.println("Connection closed"); } public void messageDelivered(TransportEvent e) { System.out.println("Message delivered for:"); if (e != null) { Address[] a = e.getValidSentAddresses(); if (a != null &amp;&amp; a.length &gt; 0) { for (int i = 0; i &lt; a.length; i++) { System.out.println(((InternetAddress) a[i]).getAddress()); } } System.out.println(""); } } public void messageNotDelivered(TransportEvent e) { System.out.println("Message not delivered for:"); if (e != null) { Address[] a = e.getValidUnsentAddresses(); if (a != null &amp;&amp; a.length &gt; 0) { for (int i = 0; i &lt; a.length; i++) { System.out.println(((InternetAddress) a[i]).getAddress()); } } System.out.println(""); } } public void messagePartiallyDelivered(TransportEvent e) { System.out.println("These addresses are invalid:"); if (e != null) { Address[] a = e.getInvalidAddresses(); if (a != null &amp;&amp; a.length &gt; 0) { for (int i = 0; i &lt; a.length; i++) { System.out.println(((InternetAddress) a[i]).getAddress()); } } System.out.println(""); } } </code></pre> <p>This is suggested in oe of the blogs. Whats wrong here? How can i get the delivery status as false for wrong mail IDS</p> <p>This is how i am initializing the message</p> <pre><code>MimeMessage message=new MimeMessage(session); //set the mail sender address message.setFrom(new InternetAddress(userName)); //set the recipient addresses message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddr)); //set subject of the mail message.setSubject(subject); //Set the body of the message message.setText(body); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload