Technocrat’s Perspective

-a technical blog

Sending Mail with attachment through JavaMail

Hi Folks,

In this article, am going to give you a sample program to send an email with attachment through JavaMail API in java program. You should have JavaMail and JavaBeans Activation Framework(if needed) to make work this program. JAF is needed when you have the JDK installed other than the version 1.6 or more. JAF is bundled with JDK1.6 and for those who use the older version can follow the download file reference link available here. JavaMail download reference link can be followed by clicking here. When you extract both these downloaded zip file, you can have the jar files named ‘activation.jar’(from JAF) and ‘mail.jar’(from JavaMail). Place these two jar files under the ‘lib’ folders of the JDK installation directory and also make the reference of these two jar files to the classpath environment variable.

I here with inline the java program to send mail with attachment.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class MailWithAttachment
{
public static void main(String[] args)
{
try
{
java.util.Properties mailprop = new java.util.Properties();
String host =  "smtp";
String fromAddress = "test@enpysoft.com";
String toAddress = "muthuselvan@adventnet.com";
String filename = "c://npselvan//invitation.tiff";
String subj = "Invitation";
String content = "Hi Friends!,\n\tI cordially invite you all guys for the seminar.\n\nRegards,\nNpselvan.";
mailprop.put("mail.smtp.host",host);
Session session = Session.getInstance(mailprop,null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(toAddress));
message.setSubject(subj);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(content);
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
message.setSentDate(new java.util.Date());
Transport.send(message);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Hope the above program could fetch idea to the beginners of Java.

Comments are Welcomed..!

Stumble for Technical

October 17, 2008 Posted by npselvan | TechBitz, Technology | , , , , , | No Comments Yet

A website for UI Designers.

Hi All,
Am not well-versed with color management and CSS in my development. I will be seeking the help of Google for every such kind of works. I surfed for any such tools and i came across the website named fonttester. Click here to have a look on the webpage. The website was really amazing, as the CSS properties will be listed down in the left pane and the subsequent changes made to the CSS properties will be reflected in the right pane message content. You can go ahead and have a look on it. Hope this web page can guide and help the Usability engineers.

Comments are Welcomed..!

Stumble for Technical

October 3, 2008 Posted by npselvan | Internet Tips, TechBitz, Technology, Tools | | No Comments Yet

QEngine Web Load Testing

Hi All,

Testing is the vital thing for every product/project and meanwhile performance should also to be taken in to account before the project/product to be delivered. AdventNet has one such product to test the web performance. If your application is on web based and through HTTP and HTTPS  protocol, you can go ahead with testing your application with load testing tool, AdventNet QEngine. How was your application responding when ‘n’ number of users are accessing your service? AdventNet QEngine come out with very powerful feature and more over the product cost is less compared to some other testing product. QEngine  is also releasing their subsequent release over periodic time. QEngine Web Load Testing tool have some load testing types. You can test your application with ramp-up mode, ramp-down mode, normal mode, burn-in mode and mixed load type mode. You can go through their online help link on the website. Moreover a couple of weeks evaluation time is given with the product and the support is given free during your evaluation. Go ahead and download the product and test your application.

Comments are Welcomed..!

Stumble for Technical

October 3, 2008 Posted by npselvan | TechBitz, Technology, Tools | | No Comments Yet