本文整理汇总了Java中org.apache.commons.mail.EmailException类的典型用法代码示例。如果您正苦于以下问题:Java EmailException类的具体用法?Java EmailException怎么用?Java EmailException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmailException类属于org.apache.commons.mail包,在下文中一共展示了EmailException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendSimpleEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
public void sendSimpleEmail(String email_to, String subject, String msg) {
SimpleEmail email = new SimpleEmail();
try {
email.setDebug(debug);
email.setHostName(smtp);
email.addTo(email_to);
email.setFrom(email_from);
email.setAuthentication(email_from, email_password);
email.setSubject(subject);
email.setMsg(msg);
email.setSSL(ssl);
email.setTLS(tls);
email.send();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例2: doSend
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
private void doSend(String recipient, String sender, Set<String> cc, String subject, String content,
EmailAttachment... attachments) throws EmailException {
HtmlEmail email = new HtmlEmail();
email.setCharset("utf-8");
for (EmailAttachment attachment : attachments) {
email.attach(attachment);
}
email.setHostName(HOST);
email.setSmtpPort(PORT);
email.setAuthenticator(new DefaultAuthenticator(USER, PWD));
email.setSSLOnConnect(USE_SSL);
email.setSubject(subject);
email.addTo(recipient);
email.setFrom(String.format("Exam <%s>", SYSTEM_ACCOUNT));
email.addReplyTo(sender);
for (String addr : cc) {
email.addCc(addr);
}
email.setHtmlMsg(content);
if (USE_MOCK) {
mockSending(email, content, attachments);
} else {
email.send();
}
}
示例3: main
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
/**
* This main method is useful when debugging smtp configuration problems.
*/
public static void main(String... argv) throws EmailException
{
// gmail : smtp.gmail.com:465
String fromEmailAddress=argv[0];
String toEmailAddress=argv[1];
String smtpServer=argv[2];
String smtpPort=(argv.length>3?argv[3]:null);
String smtpUser=(argv.length>4?argv[4]:null);
String smtpPassword=(argv.length>5?argv[4]:null);
String connectionSecurity=(argv.length>6?argv[5]:null);
HtmlEmail htmlEmail=EmailUtilsOld.getHtmlEmail(smtpServer, smtpPort, smtpUser, smtpPassword, connectionSecurity);
htmlEmail.addTo(toEmailAddress, toEmailAddress);
htmlEmail.setFrom(fromEmailAddress, fromEmailAddress);
htmlEmail.setSubject("test subject");
htmlEmail.setTextMsg("test contents "+(new java.util.Date()));
htmlEmail.send();
}
示例4: sendEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
private void sendEmail() throws EmailException
{
HtmlEmail email = new HtmlEmail();
email.setHostName(smtpServer);
if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword);
if (smtpSslPort != null)
{
email.setSSL(true);
email.setSslSmtpPort(smtpSslPort);
}
Session session = email.getMailSession();
Properties properties = session.getProperties();
properties.setProperty("mail.smtp.connectiontimeout", "20000");
properties.setProperty("mail.smtp.timeout", "20000");
email.addTo(recipientEmailAddress, recipientEmailAddress);
email.setFrom(smtpUser, smtpUser);
email.setSubject(subject);
email.setHtmlMsg(contents);
email.setTextMsg(contents);
email.send();
}
示例5: send
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
public static void send(Mail mail) {
HtmlEmail email = new HtmlEmail();
try {
email.setHostName(mail.getHost());
email.setCharset(Config.UTF_8);
email.addTo(mail.getReceiver());
email.setFrom(mail.getSender(), mail.getName());
email.setAuthentication(mail.getUsername(), mail.getPassword());
email.setSubject(mail.getSubject());
email.setMsg(mail.getMessage());
email.setSmtpPort(mail.getSmtpPort());
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
示例6: sendMailByApache
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
public static void sendMailByApache(String to, String title, String content) {
try {
HtmlEmail email = new HtmlEmail();
// 这里是发送服务器的名字
email.setHostName(smtpHost);
// 编码集的设置
email.setTLS(true);
email.setSSL(true);
email.setCharset("utf-8");
// 收件人的邮箱
email.addTo(to);
// 发送人的邮箱
email.setFrom(fromEmail);
// 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码
email.setAuthentication(username, password);
email.setSubject(title);
// 要发送的信息
email.setMsg(content);
// 发送
email.send();
} catch (EmailException e) {
Log.i("EmailUtil", e.getMessage());
}
}
示例7: getHtmlEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls,
String sender )
throws EmailException
{
HtmlEmail email = new HtmlEmail();
email.setHostName( hostName );
email.setFrom( sender, customizeTitle( DEFAULT_FROM_NAME ) );
email.setSmtpPort( port );
email.setStartTLSEnabled( tls );
if ( username != null && password != null )
{
email.setAuthenticator( new DefaultAuthenticator( username, password ) );
}
return email;
}
示例8: sendEmailForUpComingInvoice
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
private void sendEmailForUpComingInvoice(final Account account, final ExtBusEvent killbillEvent, final TenantContext context) throws IOException, InvoiceApiException, EmailException, TenantApiException, EmailNotificationException {
Preconditions.checkArgument(killbillEvent.getEventType() == ExtBusEventType.INVOICE_NOTIFICATION, String.format("Unexpected event %s", killbillEvent.getEventType()));
final String dryRunTimePropValue = configProperties.getString(INVOICE_DRY_RUN_TIME_PROPERTY);
Preconditions.checkArgument(dryRunTimePropValue != null, String.format("Cannot find property %s", INVOICE_DRY_RUN_TIME_PROPERTY));
final TimeSpan span = new TimeSpan(dryRunTimePropValue);
final DateTime now = clock.getClock().getUTCNow();
final DateTime targetDateTime = now.plus(span.getMillis());
final PluginCallContext callContext = new PluginCallContext(EmailNotificationActivator.PLUGIN_NAME, now, context.getTenantId());
final Invoice invoice = osgiKillbillAPI.getInvoiceUserApi().triggerInvoiceGeneration(account.getId(), new LocalDate(targetDateTime, account.getTimeZone()), NULL_DRY_RUN_ARGUMENTS, callContext);
if (invoice != null) {
final EmailContent emailContent = templateRenderer.generateEmailForUpComingInvoice(account, invoice, context);
sendEmail(account, emailContent, context);
}
}
示例9: test
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
/**
* send mail
*/
@Test
public void test() {
try {
HtmlEmail htmlEmail = new HtmlEmail();
htmlEmail.setHostName("smtp.qq.com");
htmlEmail.setFrom("[email protected]", "[email protected]");
htmlEmail.addTo("[email protected]");
htmlEmail.addCc("[email protected]", "[email protected]");
htmlEmail.setAuthentication("[email protected]", "TaylorSwift");
htmlEmail.setSubject("email example");
htmlEmail.setHtmlMsg("test apache email");
htmlEmail.setCharset("UTF-8");
htmlEmail.buildMimeMessage();
htmlEmail.sendMimeMessage();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例10: getHtmlEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls, String sender )
throws EmailException
{
HtmlEmail email = new HtmlEmail();
email.setHostName( hostName );
email.setFrom( defaultIfEmpty( sender, FROM_ADDRESS ), customizeTitle( DEFAULT_FROM_NAME ) );
email.setSmtpPort( port );
email.setStartTLSEnabled( tls );
if ( username != null && password != null )
{
email.setAuthenticator( new DefaultAuthenticator( username, password ) );
}
return email;
}
示例11: envia
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
public static void envia(Registrar reg) {
try {
SimpleEmail email = new SimpleEmail();
email.setHostName("10.1.8.102");
email.addTo("[email protected]");
//email.addCc("[email protected]");
email.addCc("[email protected]");
email.addCc("[email protected]");
email.addCc("[email protected]");
//email.addCc("[email protected]");
//email.addCc("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Error en tablealias");
String msg = String.format("%nServidor %s, pathInfo %s%nParametros %s ",reg.getNomServidor(), reg.getPagAccesa(), reg.getParametros());
email.setMsg("Categoria: " + reg.getCategoria() + " , Descripcion " + reg.getDescripcion() + msg + " \n Navegador:" + reg.getExplorador());
email.send();
} catch (EmailException ex1) {
ex1.printStackTrace();
}
}
示例12: sendHtmlAndTextEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
@Override
public void sendHtmlAndTextEmail(String to, String subject, String htmlBody, String textBody) throws ServiceException {
HtmlEmail email = new HtmlEmail();
try {
setupEmail(email);
validateAddress(to);
email.addTo(to);
email.setSubject(subject);
email.setHtmlMsg(htmlBody);
email.setTextMsg(textBody);
email.send();
} catch (EmailException e) {
log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
throw new ServiceException("Unable to send email.", e);
}
}
示例13: sendHtmlEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
@Override
public void sendHtmlEmail(String to, String subject, String htmlBody) throws ServiceException {
HtmlEmail email = new HtmlEmail();
try {
setupEmail(email);
validateAddress(to);
email.addTo(to);
email.setSubject(subject);
email.setHtmlMsg(htmlBody);
email.send();
} catch (EmailException e) {
log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
throw new ServiceException("Unable to send email.", e);
}
}
示例14: sendEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
/** Sends email according to the provided config. */
private static void sendEmail(SmtpConfiguration config, HtmlEmail email, String subject,
String fromAddress, String toAddress) throws EmailException {
if (config != null) {
email.setSubject(subject);
LOG.info("Sending email to {}", toAddress);
email.setHostName(config.getSmtpHost());
email.setSmtpPort(config.getSmtpPort());
if (config.getSmtpUser() != null && config.getSmtpPassword() != null) {
email.setAuthenticator(
new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPassword()));
email.setSSLOnConnect(true);
}
email.setFrom(fromAddress);
for (String address : toAddress.split(EMAIL_ADDRESS_SEPARATOR)) {
email.addTo(address);
}
email.send();
LOG.info("Email sent with subject [{}] to address [{}]!", subject, toAddress);
} else {
LOG.error("No email config provided for email with subject [{}]!", subject);
}
}
示例15: sendEmail
import org.apache.commons.mail.EmailException; //导入依赖的package包/类
public void sendEmail() {
HtmlEmail email = new HtmlEmail();
try {
email.setHostName(emailHostName);
email.setSmtpPort(smtpPort);
email.setAuthenticator(new DefaultAuthenticator(emailLogin,
emailPassword));
email.setSSLOnConnect(emailSSL);
email.setStartTLSEnabled(startTLS);
email.setFrom(emailSender);
email.setSubject(title);
email.setHtmlMsg(htmlMessage);
email.addTo(emailRecipient);
email.send();
System.out.println("Email sent: " + title);
} catch (EmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}