本文整理汇总了Java中org.apache.commons.mail.Email类的典型用法代码示例。如果您正苦于以下问题:Java Email类的具体用法?Java Email怎么用?Java Email使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Email类属于org.apache.commons.mail包,在下文中一共展示了Email类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import org.apache.commons.mail.Email; //导入依赖的package包/类
public void sendEmail(final EmailData emailData) {
try {
Email email = new SimpleEmail();
email.setHostName(smtpServer);
email.setSmtpPort(smtpPort);
email.setAuthenticator(new DefaultAuthenticator(username, password));
email.setSSLOnConnect(secure);
email.setFrom(emailData.getAddressFrom());
email.setSubject(emailData.getSubject());
email.setMsg(emailData.getMessageContent());
email.addTo(emailData.getAddressTo());
email.send();
} catch (org.apache.commons.mail.EmailException e) {
throw new EmailException(e);
}
}
示例2: configureConnection
import org.apache.commons.mail.Email; //导入依赖的package包/类
private static void configureConnection(Email email) {
try {
email.setSmtpPort(SMTP_PORT);
email.setHostName(SMTP_HOST);
email.setCharset(CHARSET);
if (!GeneralUtils.isEmpty(SMTP_USER)) {
email.setAuthentication(
SMTP_USER,
SMTP_PASSWORD
);
}
email.setSSLOnConnect(SMTP_SSL);
email.setStartTLSEnabled(SMTP_TLS);
} catch (Throwable ex) {
LOG.error("Erro ao configurar o email.", ex);
throw new RuntimeException("Error configuring smtp connection.", ex);
}
}
示例3: send
import org.apache.commons.mail.Email; //导入依赖的package包/类
protected void send(String mailAddress, String title, String content) {
if (StringUtils.isBlank(mailAddress)) {
return;
}
try {
Email email = new HtmlEmail();
email.setHostName(hostname);
email.setAuthenticator(new DefaultAuthenticator(username, password));
email.setSmtpPort(port);
email.setFrom(from, fromname);
email.setSubject(title);
email.setMsg(content);
email.addTo(mailAddress.split(mailAddressEndSeparator));
email.send();
} catch (Exception e) {
logger.error("Send Mail Error", e);
}
}
示例4: setFrom
import org.apache.commons.mail.Email; //导入依赖的package包/类
protected void setFrom(Email email, String from, String tenantId) {
String fromAddress = null;
if (from != null) {
fromAddress = from;
} else { // use default configured from address in process engine config
if (tenantId != null && tenantId.length() > 0) {
Map<String, MailServerInfo> mailServers = CommandContextUtil.getProcessEngineConfiguration().getMailServers();
if (mailServers != null && mailServers.containsKey(tenantId)) {
MailServerInfo mailServerInfo = mailServers.get(tenantId);
fromAddress = mailServerInfo.getMailServerDefaultFrom();
}
}
if (fromAddress == null) {
fromAddress = CommandContextUtil.getProcessEngineConfiguration().getMailServerDefaultFrom();
}
}
try {
email.setFrom(fromAddress);
} catch (EmailException e) {
throw new FlowableException("Could not set " + from + " as from address in email", e);
}
}
示例5: setFrom
import org.apache.commons.mail.Email; //导入依赖的package包/类
protected void setFrom(Email email, String from, String tenantId) {
String fromAddress = null;
if (from != null) {
fromAddress = from;
} else { // use default configured from address in process engine config
if (tenantId != null && tenantId.length() > 0) {
Map<String, MailServerInfo> mailServers = Context.getProcessEngineConfiguration().getMailServers();
if (mailServers != null && mailServers.containsKey(tenantId)) {
MailServerInfo mailServerInfo = mailServers.get(tenantId);
fromAddress = mailServerInfo.getMailServerDefaultFrom();
}
}
if (fromAddress == null) {
fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
}
}
try {
email.setFrom(fromAddress);
} catch (EmailException e) {
throw new ActivitiException("Could not set " + from + " as from address in email", e);
}
}
示例6: send
import org.apache.commons.mail.Email; //导入依赖的package包/类
/**
* Method to send an email.
* @param m email message to be sent.
* @return id of message that has been sent.
* @throws MailNotSentException if mail couldn't be sent.
*/
@Override
public String send(EmailMessage<Email> m) throws MailNotSentException {
if (!mEnabled) {
//don't send message if not enabled
return null;
}
//to avoid compilation errors regarding to casting
EmailMessage m2 = m;
if (m2 instanceof ApacheMailTextEmailMessage) {
return sendMultiPartEmail((ApacheMailTextEmailMessage)m2);
} else if (m2 instanceof ApacheMailTextEmailMessageWithAttachments) {
return sendMultiPartEmail((ApacheMailTextEmailMessageWithAttachments)m2);
} else if (m2 instanceof ApacheMailHtmlEmailMessage) {
return sendHtmlEmail((ApacheMailHtmlEmailMessage)m2);
} else {
throw new MailNotSentException("Unsupported email type");
}
}
示例7: send
import org.apache.commons.mail.Email; //导入依赖的package包/类
@Override
public void send(String absender, String empfaenger, String betreff, String text) {
try {
final Email email = new SimpleEmail();
email.setHostName(mailhost);
email.setSmtpPort(mailport);
email.setFrom(absender);
email.setSubject(betreff);
email.setMsg(text);
email.addTo(empfaenger);
email.send();
log.info("mail sent to: " + empfaenger);
} catch (final EmailException e) {
log.error(e.getMessage(), e);
}
}
示例8: createEmail
import org.apache.commons.mail.Email; //导入依赖的package包/类
protected Email createEmail() {
Email email = new SimpleEmail();
email.setHostName(config.readString(ConfigProperty.SMTP_HOST_NAME));
email.setSSLOnConnect(config.readBoolean(ConfigProperty.SMTP_USE_SSL));
if (config.readBoolean(ConfigProperty.SMTP_USE_SSL)) {
email.setSslSmtpPort(config.readString(ConfigProperty.SMTP_PORT));
} else {
email.setSmtpPort(config.readInt(ConfigProperty.SMTP_PORT));
}
if (config.readBoolean(ConfigProperty.SMTP_AUTH)) {
email.setAuthenticator(new DefaultAuthenticator(config.readString(ConfigProperty.SMTP_DEFAULT_USERNAME),
config.readString(ConfigProperty.SMTP_DEFAULT_PASSWORD)));
}
try {
email.setFrom(config.readString(ConfigProperty.EMAIL_DEFAULT_FROM),
config.readString(ConfigProperty.EMAIL_DEFAULT_FROM_NAME));
} catch (EmailException e) {
throw Exceptions.runtime(e);
}
email.setSocketConnectionTimeout(config.readInt(ConfigProperty.SMTP_CONNECTION_TIMEOUT));
email.setSocketTimeout(config.readInt(ConfigProperty.SMTP_SEND_TIMEOUT));
return email;
}
示例9: sendEmail
import org.apache.commons.mail.Email; //导入依赖的package包/类
private void sendEmail() throws EmailException, UnknownHostException {
List<String> addresses =
Lists.newArrayList(Splitter.on(',')
.omitEmptyStrings()
.trimResults()
.split(ADMIN_EMAIL.getAdmins()));
logger.info("Sending email to {}", addresses.toString());
Email email = new HtmlEmail();
email.setHostName(ADMIN_EMAIL.getHost());
email.setSocketTimeout(30000); // 30 seconds
email.setSocketConnectionTimeout(30000); // 30 seconds
for (String address : addresses) {
email.addTo(address);
}
email.setFrom(SorcererInjector.get().getModule().getName() + "@" +
InetAddress.getLocalHost().getHostName());
email.setSubject(title);
email.setMsg(body);
email.send();
}
示例10: sendEmail
import org.apache.commons.mail.Email; //导入依赖的package包/类
private void sendEmail(final String address, final String taskId, final String taskName, final Throwable cause)
throws Exception
{
Email mail = new SimpleEmail();
mail.setSubject("Task execution failure");
mail.addTo(address);
// FIXME: This should ideally render a user-configurable template
StringWriter buff = new StringWriter();
PrintWriter out = new PrintWriter(buff);
if (taskId != null) {
out.format("Task ID: %s%n", taskId);
}
if (taskName != null) {
out.format("Task Name: %s%n", taskName);
}
if (cause != null) {
out.println("Stack-trace:");
cause.printStackTrace(out);
}
mail.setMsg(buff.toString());
emailManager.get().send(mail);
}
示例11: sendMail
import org.apache.commons.mail.Email; //导入依赖的package包/类
private static void sendMail(String title, String message, String emailaddy) {
try {
Email email = new SimpleEmail();
email.setHostName(p.getProperty("mailserver.host"));
email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port")));
if(p.getProperty("mailserver.useauth").equals("true"))
{
email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass"));
}
if(p.getProperty("mailserver.usessl").equals("true"))
{
email.setSSLOnConnect(true);
}
else
{
email.setSSLOnConnect(false);
}
email.setFrom(p.getProperty("mailserver.from"));
email.setSubject("[MuninMX] " + title);
email.setMsg(message);
email.addTo(emailaddy);
email.send();
} catch (Exception ex) {
logger.warn("Unable to send Mail: " + ex.getLocalizedMessage());
}
}
示例12: send
import org.apache.commons.mail.Email; //导入依赖的package包/类
void send(Mail mail) {
if(logger.isTraceEnabled()) {
logger.trace("New mail to send - {}", mail.subject);
}
Email email = smtp.emptyEmail();
email.setSubject(mail.subject);
try {
email.setFrom(mail.from);
email.setTo(Arrays.asList(new InternetAddress(mail.to)));
email.setMsg(mail.body);
if(logger.isDebugEnabled()) {
logger.debug("Send mail {}", mail.subject);
}
email.send();
} catch (EmailException | AddressException e) {
throw new RuntimeException(e);
}
}
示例13: buildMessage
import org.apache.commons.mail.Email; //导入依赖的package包/类
/**
*
*/
public static Email buildMessage(Email email) throws EmailException {
String from = GojaConfig.getProperty("mail.smtp.from");
if (email.getFromAddress() == null && !StringUtils.isEmpty(from)) {
email.setFrom(from);
} else if (email.getFromAddress() == null) {
throw new MailException("Please define a 'from' email address", new NullPointerException());
}
if ((email.getToAddresses() == null || email.getToAddresses().size() == 0) &&
(email.getCcAddresses() == null || email.getCcAddresses().size() == 0) &&
(email.getBccAddresses() == null || email.getBccAddresses().size() == 0)) {
throw new MailException("Please define a recipient email address",
new NullPointerException());
}
if (email.getSubject() == null) {
throw new MailException("Please define a subject", new NullPointerException());
}
if (email.getReplyToAddresses() == null || email.getReplyToAddresses().size() == 0) {
email.addReplyTo(email.getFromAddress().getAddress());
}
return email;
}
示例14: setMailServerProperties
import org.apache.commons.mail.Email; //导入依赖的package包/类
protected void setMailServerProperties(Email email) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
String host = processEngineConfiguration.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured");
}
email.setHostName(host);
int port = processEngineConfiguration.getMailServerPort();
email.setSmtpPort(port);
String user = processEngineConfiguration.getMailServerUsername();
String password = processEngineConfiguration.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
}
示例15: setMsg
import org.apache.commons.mail.Email; //导入依赖的package包/类
/**
* Set the message.
*
* <p>This method overrides the MultiPartEmail setMsg() method in
* order to send an HTML message instead of a full text message in
* the mail body. The message is formatted in HTML for the HTML
* part of the message, it is let as is in the alternate text
* part.
*
* @param msg A String.
* @return An Email.
* @throws EmailException see javax.mail.internet.MimeBodyPart
* for definitions
*
*/
public Email setMsg(String msg) throws EmailException {
if (StringUtil.isEmpty(msg)) {
throw new EmailException("Invalid message supplied");
}
setTextMsg(msg);
setHtmlMsg(
new StringBuffer()
.append("<html><body><pre>")
.append(msg)
.append("</pre></body></html>")
.toString());
return this;
}