Thursday, March 29, 2007

Using To Send Mail

Here is a snippet of code I wrote to use to send mails.
Please use vaild email address.

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

* @author prasad

public class MailInfo {
public void send() throws EmailException {
Email email = new SimpleEmail();
String authuser = "";
String authpwd = "**********";
// Very Important, Don't use email.setAuthentication()
email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd));
email.setDebug(false); // true if you want to debug
"mail.smtp.starttls.enable", "true");

email.setFrom("", "SenderName");

email.setMsg("This is a test mail?");

email.addTo("", "ToName");

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?