|
|
@ -120,34 +120,36 @@ public class MailEngine { |
|
|
|
public static void send(InternetAddress from, InternetAddress to, String subject, String body) |
|
|
|
public static void send(InternetAddress from, InternetAddress to, String subject, String body) |
|
|
|
throws MailEngineException { |
|
|
|
throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, new InternetAddress[] {to}, null, null, subject, body, false, null, null, null); |
|
|
|
send(from, new InternetAddress[] { to }, null, null, subject, body, false, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress to, String subject, String body, boolean htmlFormat) |
|
|
|
public static void send(InternetAddress from, InternetAddress to, String subject, String body, |
|
|
|
throws MailEngineException { |
|
|
|
boolean htmlFormat) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, new InternetAddress[] {to}, null, null, subject, body, htmlFormat, null, null, null); |
|
|
|
send(from, new InternetAddress[] { to }, null, null, subject, body, htmlFormat, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, |
|
|
|
InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, |
|
|
|
InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, |
|
|
|
String messageId, String inReplyTo) throws MailEngineException { |
|
|
|
boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo) |
|
|
|
|
|
|
|
throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); |
|
|
|
send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, |
|
|
|
InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, |
|
|
|
InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, |
|
|
|
String messageId, String inReplyTo, List<FileAttachment> fileAttachments) throws MailEngineException { |
|
|
|
boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo, |
|
|
|
|
|
|
|
List<FileAttachment> fileAttachments) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, fileAttachments, |
|
|
|
send(from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, messageId, inReplyTo, |
|
|
|
null); |
|
|
|
fileAttachments, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, |
|
|
|
InternetAddress[] bulkAddresses, String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, |
|
|
|
InternetAddress[] bcc, InternetAddress[] bulkAddresses, String subject, String body, |
|
|
|
String messageId, String inReplyTo, List<FileAttachment> fileAttachments, SMTPAccount smtpAccount) |
|
|
|
boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo, |
|
|
|
throws MailEngineException { |
|
|
|
List<FileAttachment> fileAttachments, SMTPAccount smtpAccount) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
|
@ -169,7 +171,8 @@ public class MailEngine { |
|
|
|
|
|
|
|
|
|
|
|
FileAttachment fileAttachment = fileAttachments.get(i); |
|
|
|
FileAttachment fileAttachment = fileAttachments.get(i); |
|
|
|
if (fileAttachment instanceof it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) { |
|
|
|
if (fileAttachment instanceof it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) { |
|
|
|
((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment).generateFile(); |
|
|
|
((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment) |
|
|
|
|
|
|
|
.generateFile(); |
|
|
|
} |
|
|
|
} |
|
|
|
File file = fileAttachment.getFile(); |
|
|
|
File file = fileAttachment.getFile(); |
|
|
|
|
|
|
|
|
|
|
@ -331,22 +334,21 @@ public class MailEngine { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, |
|
|
|
String subject, String body) throws MailEngineException { |
|
|
|
InternetAddress[] bcc, String subject, String body) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, to, cc, bcc, subject, body, false, null, null, null); |
|
|
|
send(from, to, cc, bcc, subject, body, false, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, |
|
|
|
String subject, String body, boolean htmlFormat, InternetAddress[] replyTo, String messageId, String inReplyTo) |
|
|
|
InternetAddress[] bcc, String subject, String body, boolean htmlFormat, |
|
|
|
throws MailEngineException { |
|
|
|
InternetAddress[] replyTo, String messageId, String inReplyTo) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, to, cc, bcc, null, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); |
|
|
|
send(from, to, cc, bcc, null, subject, body, htmlFormat, replyTo, messageId, inReplyTo, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, |
|
|
|
send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, String subject, String body) |
|
|
|
String body) throws MailEngineException { |
|
|
|
throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send(from, to, cc, null, subject, body, false, null, null, null); |
|
|
|
send(from, to, cc, null, subject, body, false, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
@ -363,18 +365,18 @@ public class MailEngine { |
|
|
|
send(from, to, null, null, subject, body, false, null, null, null); |
|
|
|
send(from, to, null, null, subject, body, false, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, String subject, String body, boolean htmlFormat) |
|
|
|
public static void send(InternetAddress from, InternetAddress[] to, String subject, String body, |
|
|
|
throws MailEngineException { |
|
|
|
boolean htmlFormat) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(from, to, null, null, subject, body, htmlFormat, null, null, null); |
|
|
|
send(from, to, null, null, subject, body, htmlFormat, null, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(MailMessage mailMessage) throws MailEngineException { |
|
|
|
public static void send(MailMessage mailMessage) throws MailEngineException { |
|
|
|
|
|
|
|
|
|
|
|
send(mailMessage.getFrom(), mailMessage.getTo(), mailMessage.getCC(), mailMessage.getBCC(), mailMessage |
|
|
|
send(mailMessage.getFrom(), mailMessage.getTo(), mailMessage.getCC(), mailMessage.getBCC(), |
|
|
|
.getBulkAddresses(), mailMessage.getSubject(), mailMessage.getBody(), mailMessage.isHTMLFormat(), mailMessage |
|
|
|
mailMessage.getBulkAddresses(), mailMessage.getSubject(), mailMessage.getBody(), |
|
|
|
.getReplyTo(), mailMessage.getMessageId(), mailMessage.getInReplyTo(), mailMessage.getFileAttachments(), |
|
|
|
mailMessage.isHTMLFormat(), mailMessage.getReplyTo(), mailMessage.getMessageId(), |
|
|
|
mailMessage.getSMTPAccount()); |
|
|
|
mailMessage.getInReplyTo(), mailMessage.getFileAttachments(), mailMessage.getSMTPAccount()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void send(String from, String to, String subject, String body) throws MailEngineException { |
|
|
|
public static void send(String from, String to, String subject, String body) throws MailEngineException { |
|
|
@ -425,9 +427,11 @@ public class MailEngine { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (account.isSecure()) { |
|
|
|
if (account.isSecure()) { |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.class", "javax.net.ssl.SSLSocketFactory"); |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.class", |
|
|
|
|
|
|
|
"javax.net.ssl.SSLSocketFactory"); |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.fallback", "false"); |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.fallback", "false"); |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.port", String.valueOf(account.getPort())); |
|
|
|
properties.setProperty("mail." + protocol + ".socketFactory.port", |
|
|
|
|
|
|
|
String.valueOf(account.getPort())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return properties; |
|
|
|
return properties; |
|
|
@ -444,7 +448,8 @@ public class MailEngine { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private static boolean _isThrowsExceptionOnFailure() {
|
|
|
|
// private static boolean _isThrowsExceptionOnFailure() {
|
|
|
|
// return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.MAIL_THROWS_EXCEPTION_ON_FAILURE));
|
|
|
|
// return
|
|
|
|
|
|
|
|
// GetterUtil.getBoolean(PropsUtil.get(PropsKeys.MAIL_THROWS_EXCEPTION_ON_FAILURE));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
private static void _send(Session session, Message message, InternetAddress[] bulkAddresses, int batchSize) |
|
|
|
private static void _send(Session session, Message message, InternetAddress[] bulkAddresses, int batchSize) |
|
|
@ -459,7 +464,8 @@ public class MailEngine { |
|
|
|
|
|
|
|
|
|
|
|
if (smtpAuth && Validator.isNotNull(user) && Validator.isNotNull(password)) { |
|
|
|
if (smtpAuth && Validator.isNotNull(user) && Validator.isNotNull(password)) { |
|
|
|
|
|
|
|
|
|
|
|
String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol"), Account.PROTOCOL_SMTP); |
|
|
|
String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol"), |
|
|
|
|
|
|
|
Account.PROTOCOL_SMTP); |
|
|
|
|
|
|
|
|
|
|
|
Transport transport = session.getTransport(protocol); |
|
|
|
Transport transport = session.getTransport(protocol); |
|
|
|
|
|
|
|
|
|
|
@ -504,8 +510,8 @@ public class MailEngine { |
|
|
|
} catch (MessagingException me) { |
|
|
|
} catch (MessagingException me) { |
|
|
|
if (me.getNextException() instanceof SocketException) { |
|
|
|
if (me.getNextException() instanceof SocketException) { |
|
|
|
if (_log.isWarnEnabled()) { |
|
|
|
if (_log.isWarnEnabled()) { |
|
|
|
_log.warn("Failed to connect to a valid mail server. Please " + "make sure one is properly configured. " |
|
|
|
_log.warn("Failed to connect to a valid mail server. Please " |
|
|
|
+ me.getMessage()); |
|
|
|
+ "make sure one is properly configured. " + me.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogUtil.log(_log, me); |
|
|
|
LogUtil.log(_log, me); |
|
|
|