Search in sources :

Example 21 with EmailException

use of org.apache.commons.mail.EmailException in project killbill by killbill.

the class DefaultEmailSender method sendHTMLEmail.

@Override
public void sendHTMLEmail(final List<String> to, final List<String> cc, final String subject, final String htmlBody) throws EmailApiException {
    final HtmlEmail email = new HtmlEmail();
    try {
        email.setHtmlMsg(htmlBody);
    } catch (EmailException e) {
        throw new EmailApiException(e, ErrorCode.EMAIL_SENDING_FAILED);
    }
    sendEmail(to, cc, subject, email);
}
Also used : HtmlEmail(org.apache.commons.mail.HtmlEmail) EmailException(org.apache.commons.mail.EmailException)

Example 22 with EmailException

use of org.apache.commons.mail.EmailException in project pinot by linkedin.

the class AlertTaskRunnerV2 method sendFailureEmail.

private void sendFailureEmail(Throwable t) throws JobExecutionException {
    HtmlEmail email = new HtmlEmail();
    String subject = String.format("[ThirdEye Anomaly Detector] FAILED ALERT ID=%d for config %s", alertConfig.getId(), alertConfig.getName());
    String textBody = String.format("%s%n%nException:%s", alertConfig.toString(), ExceptionUtils.getStackTrace(t));
    try {
        EmailHelper.sendEmailWithTextBody(email, thirdeyeConfig.getSmtpConfiguration(), subject, textBody, thirdeyeConfig.getFailureFromAddress(), thirdeyeConfig.getFailureToAddress());
    } catch (EmailException e) {
        throw new JobExecutionException(e);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) HtmlEmail(org.apache.commons.mail.HtmlEmail) EmailException(org.apache.commons.mail.EmailException)

Example 23 with EmailException

use of org.apache.commons.mail.EmailException in project graylog2-server by Graylog2.

the class AlarmCallbacksResource method test.

@POST
@Timed
@Path("/{alarmCallbackId}/test")
@ApiOperation(value = "Send a test alert for a given alarm callback")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alarm callback not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 500, message = "Error while testing alarm callback") })
@NoAuditEvent("only used to test alert notifications")
public Response test(@ApiParam(name = "alarmCallbackId", value = "The alarm callback id to send a test alert for.", required = true) @PathParam("alarmCallbackId") String alarmCallbackId) throws TransportConfigurationException, EmailException, NotFoundException {
    final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
    final String streamId = alarmCallbackConfiguration.getStreamId();
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final DummyAlertCondition testAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
    try {
        AbstractAlertCondition.CheckResult checkResult = testAlertCondition.runCheck();
        AlarmCallback alarmCallback = alarmCallbackFactory.create(alarmCallbackConfiguration);
        alarmCallback.call(stream, checkResult);
    } catch (Exception e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
    return Response.ok().build();
}
Also used : InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) EmailException(org.apache.commons.mail.EmailException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 24 with EmailException

use of org.apache.commons.mail.EmailException in project SpringStepByStep by JavaProgrammerLB.

the class JavaMailDemo method sendSimpleTextMail.

//	@Test
public void sendSimpleTextMail() {
    try {
        Email email = new SimpleEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("username", "password"));
        email.setSSLOnConnect(true);
        email.setFrom("username");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("foo@bar.com");
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}
Also used : Email(org.apache.commons.mail.Email) SimpleEmail(org.apache.commons.mail.SimpleEmail) ImageHtmlEmail(org.apache.commons.mail.ImageHtmlEmail) HtmlEmail(org.apache.commons.mail.HtmlEmail) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) EmailException(org.apache.commons.mail.EmailException) DefaultAuthenticator(org.apache.commons.mail.DefaultAuthenticator) SimpleEmail(org.apache.commons.mail.SimpleEmail)

Example 25 with EmailException

use of org.apache.commons.mail.EmailException in project SpringStepByStep by JavaProgrammerLB.

the class JavaMailDemo method sendEmailWithHtml.

//	@Test
public void sendEmailWithHtml() {
    try {
        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setSSLOnConnect(true);
        email.setFrom("username", "LIUBEI");
        email.addTo("admin@yitianyigexiangfa.com", "ADMIN");
        email.setAuthentication("username", "password");
        // embed the image and get the content id
        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
        String cid = email.embed(url, "Apache logo");
        // set the html message
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");
        // set the alternative message
        email.setTextMsg("Your email client does not support HTML messages");
        // send the email
        email.send();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ImageHtmlEmail(org.apache.commons.mail.ImageHtmlEmail) HtmlEmail(org.apache.commons.mail.HtmlEmail) EmailException(org.apache.commons.mail.EmailException) URL(java.net.URL)

Aggregations

EmailException (org.apache.commons.mail.EmailException)29 HtmlEmail (org.apache.commons.mail.HtmlEmail)18 Email (org.apache.commons.mail.Email)7 MultiPartEmail (org.apache.commons.mail.MultiPartEmail)7 EmailAttachment (org.apache.commons.mail.EmailAttachment)5 ExecutionException (java.util.concurrent.ExecutionException)4 SimpleEmail (org.apache.commons.mail.SimpleEmail)4 RenderResult (cn.bran.japid.template.RenderResult)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 InternetAddress (javax.mail.internet.InternetAddress)3 ImageHtmlEmail (org.apache.commons.mail.ImageHtmlEmail)3 VelocityContext (org.apache.velocity.VelocityContext)3 MailException (cn.bran.play.exceptions.MailException)2 Status (com.ctrip.platform.dal.daogen.domain.Status)2