JavaMail - Managing undeliverable feedback, notification

H

himgi

Hi to all,
I'd like to know how to catch the unliverable messages.

I'm sending email through my class below, but I cannot catch if a
message is not arrived, if the email is wrong and if the receiver has
received my message.
I could I catch all these things?
Where do I find a complete list headers for JavaMail?

Thanks in advance, Himgi.

--- START ---

import java.util.Properties;

import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;

public class MailExample implements TransportListener,
ConnectionListener {

/**
*
*/
public MailExample() {
super();
}

public static void main(String[] args) throws Exception {
MailExample example = new MailExample();
example.test();
}

public void test() throws Exception {

// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", "myownsmtpserver"); // the smtp is valid

// Get session
Session session = Session.getInstance(props, null);

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("(e-mail address removed)"));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("(e-mail address removed)"));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("(e-mail address removed)));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("(e-mail address removed)"));

message.addHeader("Reply-To", "(e-mail address removed)");
message.addHeader("Return-Receipt-To", "(e-mail address removed)");
message.addHeader("X-Mailer", "JavaMail API");
message.setSentDate(new Date());

message.setSubject("Testing JavaMail");
message.setText("POWER S.S. LAZIO");

SMTPMessage msg = new SMTPMessage(message);

// Send message
Transport transport = session.getTransport("smtp");
transport.addConnectionListener(this);
transport.addTransportListener(this);
transport.connect();
transport.sendMessage(msg, msg.getAllRecipients());

transport.close();

System.out.println("\nMail was sent successfully.");
}

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 && a.length > 0) {
for (int i = 0; i < a.length; i++) {
System.out.println(((InternetAddress) a).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 && a.length > 0) {
for (int i = 0; i < a.length; i++) {
System.out.println(((InternetAddress) a).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 && a.length > 0) {
for (int i = 0; i < a.length; i++) {
System.out.println(((InternetAddress) a).getAddress());
}
}
System.out.println("");
}
}

}

--- END ---
 
T

Timo Stamm

himgi said:
Hi to all,
I'd like to know how to catch the unliverable messages.

You can't. JavaMail just hands the message over to the local MTA. The
MTA is responsible for delivering the mail.


Where do I find a complete list headers for JavaMail?

There are no specific headers for JavaMail. You can put anything in the
headers you want.

See this list of common headers:

http://www.faqs.org/rfcs/rfc2076.html


Timo
 
R

Roedy Green

There are no specific headers for JavaMail. You can put anything in the
headers you want

to get an idea of the sort of thing you might like to setup, look at
mail your standalone mailer sends or the headers from others.
 
T

Thomas Weidenfeller

Roedy said:
to get an idea of the sort of thing you might like to setup, look at
mail your standalone mailer sends or the headers from others.

I would really suggest not to work from examples, but from the RFCs.
There are just to many broken mail clients out there which are very bad
examples.

Looking at mail clients (more than one, non of these from Microsoft)
could maybe provide additional information, but is no substitute for the
standard.

/Thomas
 
R

Roedy Green

I would really suggest not to work from examples, but from the RFCs.
There are just to many broken mail clients out there which are very bad
examples.

Looking at mail clients (more than one, non of these from Microsoft)
could maybe provide additional information, but is no substitute for the
standard.

My advice still stands. Examples help you understand what something
is for, what is in commonly use etc. Examples help sort out the
esoteric never-used stuff from the near mandatory. Then go read your
RFC. with that background and it will make a lot more sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top