Mail API - SEND MAIL‏

package demo.util;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.log4j.Logger;
import demo.CRM;

public class Mail {
    static Logger logger = Logger.getLogger(Mail.class);

    /**
     *
     * @param smtpHost
     * @param smtpPort
     * @param from
     * @param to
     * @param subject
     * @param content
     * @throws AddressException
     * @throws MessagingException
     */
    public static void send(String smtpHost, String smtpPort, String from, String to, String subject,
            String content) throws AddressException,MessagingException {
        // Create a mail session
        Properties props = new Properties();
        props.put("mail.smtp.host", smtpHost);
        props.put("mail.smtp.port", smtpPort);
        Session session = Session.getDefaultInstance(props, null);
        logger.debug("SMTP session created with host " + smtpHost + " and port " + smtpPort);
        // Construct the message
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(from));
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
        msg.setSubject(subject);
        msg.setText(content);
        logger.info("Sending message to " + to);
        Transport.send(msg);
        logger.info("Email sent succesfully to " + to);
    }

    /**
     *
     * @param to
     * @param subject
     * @param content
     * @throws AddressException
     * @throws MessagingException
     */
    public static void send(String to, String subject, String content) throws AddressException,
            MessagingException {
        send (PropertyManager.getInstance().getString("mail.smtp.host"),
                PropertyManager.getInstance().getString("mail.smtp.port"),
                PropertyManager.getInstance().getString("mail.address.from"),
                to,subject,content);
    }
 
}