Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Decompiled by Procyon v0.5.30
- //
- package com.tw.manage.business.services;
- import java.util.Hashtable;
- import java.util.Iterator;
- import javax.mail.Transport;
- import javax.mail.MessagingException;
- import javax.mail.Address;
- import javax.mail.Message;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.mail.Authenticator;
- import javax.mail.Session;
- import java.util.Properties;
- import com.tw.manage.business.ManageException;
- import java.util.List;
- import org.apache.log4j.Logger;
- public class MailService
- {
- private static Logger log;
- public static void sendMessage(final List<String> toEmails, final List<String> ccEmails, final String subject, final String content) throws ManageException {
- final String fromEmail = PropertyService.getProperty("mailer.from");
- sendMessage(toEmails, ccEmails, fromEmail, subject, content);
- }
- public static void sendMessage(final List<String> toEmails, final List<String> ccEmails, final String fromEmail, final String subject, final String content) throws ManageException {
- if (fromEmail == null || fromEmail.equalsIgnoreCase("")) {
- throw new ManageException("From email address is required.");
- }
- Transport t = null;
- final StringBuffer logMessage = new StringBuffer();
- try {
- final String host = PropertyService.getProperty("mailer.smtp.host");
- final String user = PropertyService.getProperty("mailer.user");
- final String password = PropertyService.getProperty("mailer.password");
- final String protocol = PropertyService.getProperty("mailer.protocol");
- final String port = PropertyService.getProperty("mailer.smtp.port");
- final String mimeType = PropertyService.getProperty("mailer.mime.type");
- final String subjectMimeType = PropertyService.getProperty("mailer.subject.mime.type");
- final Properties props = new Properties();
- ((Hashtable<String, String>)props).put("mail.smtp.host", host);
- ((Hashtable<String, String>)props).put("mail.smtp.port", port);
- ((Hashtable<String, String>)props).put("mail.smtp.starttls.enable", "true");
- ((Hashtable<String, String>)props).put("mail." + protocol + ".auth", "true");
- final Session session = Session.getDefaultInstance(props, (Authenticator)null);
- session.setDebug(false);
- final MimeMessage msg = new MimeMessage(session);
- logMessage.append("TO: ");
- for (final String toEmail : toEmails) {
- final InternetAddress toAddress = new InternetAddress(toEmail);
- msg.addRecipient(Message.RecipientType.TO, (Address)toAddress);
- logMessage.append(toEmail).append(",");
- }
- logMessage.append(" CC: ");
- if (ccEmails != null) {
- for (final String ccEmail : ccEmails) {
- final InternetAddress ccAddress = new InternetAddress(ccEmail);
- msg.addRecipient(Message.RecipientType.CC, (Address)ccAddress);
- logMessage.append(ccEmail).append(",");
- }
- }
- msg.setSubject(subject, subjectMimeType);
- logMessage.append(" FROM: ").append(fromEmail);
- logMessage.append(" SUBJECT: ").append(subject);
- msg.setContent((Object)content, mimeType);
- final InternetAddress addressFrom = new InternetAddress(fromEmail);
- msg.setFrom((Address)addressFrom);
- t = session.getTransport(protocol);
- t.connect(host, user, password);
- t.sendMessage((Message)msg, msg.getAllRecipients());
- MailService.log.info((Object)((Object)logMessage + " - SENT"));
- }
- catch (MessagingException e) {
- MailService.log.error((Object)((Object)logMessage + " - NOT SENT "), (Throwable)e);
- throw new ManageException("Cannot send email.", (Throwable)e);
- }
- finally {
- try {
- t.close();
- }
- catch (MessagingException e2) {
- MailService.log.error((Object)"Cannot close email transport.", (Throwable)e2);
- }
- }
- }
- static {
- MailService.log = Logger.getLogger((Class)MailService.class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment