Sunday, April 22, 2007

[completeJava] Sending Email Using Apache Commons

 

import org.apache.commons.mail .*;

public class  EmailDemo
{
 public static void main(String[] args) throws Exception
 {
  sendSimpleEmail();
 }
 public static void sendSimpleEmail(){
  SimpleEmail email = new SimpleEmail();
  email.setHostName("hostName");
  email.addTo("thirupathi@renintech.com", "Thirupathi");
  email.setFrom("thirupathi@renintech.com", "Me");
  email.setSubject("Test message");
  email.setMsg("This is a simple test of commons-email");
  email.send();
 }

 public static void sendEmailWithAttach(){
  EmailAttachment attachment = new EmailAttachment();
  attachment.setPath("EmailDemo.java");
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("This Java Program");
  attachment.setName("Thirupathi");

  // Create the email message
  MultiPartEmail email = new MultiPartEmail();
  email.setHostName("HostName");
  email.addTo("b.thirupathi@yahoo.com", "Thirupathi");
  email.setFrom("thirupathi@renintech.com", "Me");
  email.setSubject("The picture");
  email.setMsg("Java Program for Sending email with attachment");

  // add the attachment
  email.attach(attachment);

  // send the email
  email.send();
 }
}

 

for required jar files download http-email-commons.jar file from Files Section of completeJava Group

__._,_.___
Recent Activity
Visit Your Group
SPONSORED LINKS
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___

No comments: