want sample code for JavaMail Events
I have wriiten a simple code for sending mail.It works fine, but doesn't give any notification i.e. whether mail is deleivered or not ,wrong value for receiptant.
I guess Transport event class can be used for this puspose
I want sample code for JavaMail Events.
Please confirm whether i am correct or not?
if i am wrong plese give me another solution
i am attching part of my code
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
class mailchk
{
public static void main(String[] args)
{
try{
String to="**************@sigmasoft.biz";
String from="*************@sigmasoft.biz";
String subject="cheking";
String message="this is a testing mail from java program";
System.out.println("Hello World!");
Properties props1 = new Properties();
props1.put("mail.transport.protocol", "smtp");
props1.put("mail.smtp.starttls.enable","true");
props1.put("mail.smtp.host", "193.168.1.4");
props1.put("mail.debug", "true" );
//Authenticator auth = (new mailchk()).new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props1);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(message, "text/plain");
Transport.send(msg);
}catch(MessagingException e )
{
System.out.println("exception occurs");
//e.printStackTrace();
System.out.println(e.getMessage().toString());
}
catch(Exception e )
{
System.out.println(" root exception occurs");
}
}
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = "prithvirajm";
String password = "welcome";
return new PasswordAuthentication(username, password);
}
}
}
waitng for reply

