package org.wyona.yanel.impl.resources.contactform;

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;

/**
 *
 */
public class SendMail {
    private static Logger log = Logger.getLogger(SendMail.class);

    public static final String STATUS = "status";
    public static final String MESSAGE = "message";
    
    /**
     *
     */
    public static void send(String smtpHost, int smtpPort, String from, String to, String subject, String content) throws AddressException, MessagingException {

        // Create a mail session
        Session session = null;
        if (smtpHost != null && smtpPort >= 0) {
            java.util.Properties props = new java.util.Properties();
            props.put("mail.smtp.host", smtpHost);
            props.put("mail.smtp.port", "" + smtpPort);
            session = Session.getInstance(props, null);
            log.warn("Use specific mail session: " + session.getProperty("mail.smtp.host") + ":" + session.getProperty("mail.smtp.port"));
        } else {
            java.util.Properties props = new java.util.Properties();
            props.put("mail.smtp.host", "mail.foo.bar"); // Dummy value
            props.put("mail.smtp.port", "37"); // Dummy value
            session = Session.getDefaultInstance(props, null);
            log.warn("Use default mail session: " + session.getProperty("mail.smtp.host") + ":" + session.getProperty("mail.smtp.port"));
        }

        // 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);

        // Send the message
        Transport.send(msg);
    }
}

@@ -50,35 +50,8 @@
 m;%0A%0A
-import javax.mail.Message;%0A
 impo
@@ -106,432 +106,303 @@
 ail.
-Session;%0Aimport javax.mail.Transport;%0Aimport javax.mail.internet.AddressException;%0Aimport javax.mail.internet.InternetAddress;%0Aimport javax.mail.internet.MimeMessage;%0A%0Aimport org.apache.log4j.Logger;%0A%0A/**%0A *%0A */%0Apublic class SendMail %7B%0A    private static Logger log = Logger.getLogger(SendMail.class);%0A%0A    public static final String STATUS = %22status%22;%0A    public static final String MESSAGE = %22message%22;%0A    %0A    /**%0A     *
+internet.AddressException;%0A%0Aimport org.apache.log4j.Logger;%0A%0A/**%0A * @deprecated Use org.wyona.yanel.core.util.MailUtil instead%0A */%0Apublic class SendMail %7B%0A    private static Logger log = Logger.getLogger(SendMail.class);%0A%0A    /**%0A     * @deprecated Use org.wyona.yanel.core.util.MailUtil instead
 %0A   
@@ -567,25 +567,24 @@
 ption %7B%0A
-%0A
         
 // Creat
@@ -579,1241 +579,126 @@
     
-// Create a mail session%0A        Session session = null;%0A        if (smtpHost != null && smtpPort %3E= 0) %7B%0A            java.util.Properties props = new java.util.Properties();%0A            props.put(%22mail.smtp.host%22, smtpHost);%0A            props.put(%22mail.smtp.port%22, %22%22 + smtpPort);%0A            session = Session.getInstance(props, null);%0A            log.warn(%22Use specific mail session: %22 + session.getProperty(%22mail.smtp.host%22) + %22:%22 + session.getProperty(%22mail.smtp.port%22));%0A        %7D else %7B%0A            java.util.Properties props = new java.util.Properties();%0A            props.put(%22mail.smtp.host%22, %22mail.foo.bar%22); // Dummy value%0A            props.put(%22mail.smtp.port%22, %2237%22); // Dummy value%0A            session = Session.getDefaultInstance(props, null);%0A            log.warn(%22Use default mail session: %22 + session.getProperty(%22mail.
+log.warn(%22DEPRECATED%22);%0A        org.wyona.yanel.core.util.MailUtil.send(
 smtp
-.host%22) + %22:%22 + session.getProperty(%22mail.
+Host, 
 smtp
-.port%22));%0A        %7D%0A%0A        // Construct the message%0A        Message msg = new MimeMessage(session);%0A        msg.setFrom(new InternetAddress(from));%0A        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));%0A        msg.setSubject(subject);%0A        msg.setText(content);%0A%0A        // Send the message%0A        Transport.send(msg
+Port, from, to, subject, content
 );%0A 

use MailUtil class and set this class to deprecated