package com.fm.vj.view.utils;
import com.tangosol.dev.assembler.New;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import oracle.adf.share.logging.ADFLogger;
import oracle.net.aso.n;
public class SendEmailUtil {
public static final ADFLogger LOGGER = ADFLogger.createADFLogger(SendEmailUtil.class);
/**
* @param to
* @param cc
* @param from
* @param subject
* @param text
*/
public static void getUtility(String to,String cc, String from, String subject, String text) {
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
ResourceBundle rb = ResourceBundle.getBundle("com.jnj.brvo.view.bundles.BravoAppUIBundle");
String host = rb.getString("SMTP_HOST"); //SMTP_HOST=SMTP.NA.FM.COM
properties.setProperty("mail.smtp.host", host);
// properties.setProperty("mail.smtp.port", "25");
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
// message.addRecipient(Message.RecipientType.TO, new InternetAddress.parse(to));
if (to.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
if (cc.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
else
message.setRecipient(Message.RecipientType.CC, new InternetAddress(cc));
// Set Subject: header field
message.setSubject(subject);
// Now set the actual message
message.setText(text);
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
String messageText =
"Warning/INFO : EMail works on the BOX . Cannot be sent from local machine; The host is " + host + "";
FacesMessage fm = new FacesMessage(messageText);
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
e.printStackTrace();
}
}
}