Sending Mail in Java

String To=request.getParameter("to");
String From=request.getParameter("from");
String CC=request.getParameter("cc");
String Subject=request.getParameter("subject");
String MessageTxt = request.getParameter("message");
//Mail Starts
String smtpPort = "25";
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.host", "192.168.100.150");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", smtpPort);
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(From));
InternetAddress[] addressForMail = InternetAddress.parse(To);
msg.setRecipients(Message.RecipientType.TO, addressForMail);
msg.setSubject(Subject);
msg.setSentDate(new java.util.Date());
msg.setContent(MessageTxt, "text/html");
Transport.send(msg);            
//Mail Ends
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s