Implementation - continued....

Ist Phase
This phase includes the starting of mailing functionality at a particular client in the system. The JAVAMAIL API is used to get the required functionality. The architecture for the JavaMail is shown below:


The code fragment shown below is a simple mail client that can be used to send a mail
Properties properties = new Properties();
properties.put("mail.smtp.host", "164.164.45.10");
properties.put("mail.from", "AMS CLIENT");

The above shown lines are used to set up the properties for the mail client. The first line creates an instance of Properties class and second and third lines set up the mailing host to use and parameter for FROM field of the message to CLIENT.

The code shown below creates a Session class instance, which is used to define the session. It takes a properties instance as parameter and generates a session with the smtp host specified.
The next session of code creates a new message instance which takes as input the session created by session instance and sets the various fields like the recipients, copy to and then it tries to send the message.

try{
InternetAddress[] address= {new InternetAddress(strTo)};
msg.setSubject("alertno="+alertno+"*" );
msg.setFrom(new InternetAddress(strFrom));

//To be picked from database
//create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(strMsgText);
//create the multiparts
Multipart mp = new MimeMultipart();
mp.addBodypart(mbp1);
//create the second message part
if(!attach.equals("0"))
{
MimeBodyPart mbp2 = new MimeBodyPart();
//attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp. AddBodyPart(mbp2);

//add the multipart to the message
msg.setContent(mp);
//send the message
Transport trans = session.getTransport("smtp");
trans.connect(host, username, password);
msg.saveChanges();
trans.sendMessage(msg, address);
trans.close();

}

 


 

  Java Alert Notification System Home Page

   Previous    Next  
 

UNIVERSAL TEACHER PUBLICATIONS
Web: universalteacherpublications.com, universalteacher.com, universalteacher4u.com