Example usage for org.springframework.mail MailException getMessage

List of usage examples for org.springframework.mail MailException getMessage

Introduction

In this page you can find the example usage for org.springframework.mail MailException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:example.web.EmailController.java

private String sendMail(String subject) {
    String results = "Failed to send message: ";
    try {/* ww w.  ja  v  a 2s.c  o  m*/
        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
        msg.setSubject(subject);
        this.mailSender.send(msg);
        results = "Sent message with subject '" + subject + "'!";
    } catch (MailException ex) {
        results += ex.getMessage();
        System.err.println(results);
        ex.printStackTrace();
    }
    return results;
}

From source file:services.MailServiceTest.java

@Ignore
@Test//from w w w  . j  av  a  2s .c o  m
public void sendEmailTest() {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo("info@pncomp.com");
    msg.setFrom("ziaziek@poczta.fm");
    msg.setSubject("AAA");
    msg.setText("TEST");
    Assert.assertEquals("info@pncomp.com", msg.getTo()[0]);
    Assert.assertEquals("AAA", msg.getSubject());
    try {
        mailSender.send(msg);
    } catch (MailException ex) {
        fail(ex.getMessage());
    }

}

From source file:com.wury.app.serviceimpl.EmailSenderServiceImpl.java

@Override
public boolean sendEmail(EmailSenderModel e) {
    boolean res;/*w w w .  j a  v a 2 s  .com*/
    SimpleMailMessage mail = new SimpleMailMessage();
    mail.setTo(e.getAlamatEmailTujuan());
    mail.setSubject(e.getSubject());
    mail.setText(e.getMessageBody());
    try {
        mailSender.send(mail);
        res = true;
    } catch (MailException ex) {
        res = false;
        System.out.println(ex.getMessage());
    }
    return res;
}

From source file:csns.util.MassMailSender.java

public void send(SimpleMailMessage email, List<String> addresses) {
    List<String> bccAddresses = new ArrayList<String>();
    for (int i = 0; i < addresses.size(); ++i) {
        if (!addresses.get(i).endsWith("@localhost"))
            bccAddresses.add(addresses.get(i));
        if (bccAddresses.size() >= maxRecipientsPerMessage
                || bccAddresses.size() > 0 && i == addresses.size() - 1) {
            email.setBcc(bccAddresses.toArray(new String[0]));
            try {
                mailSender.send(email);// w w w  .jav a2  s  . com
            } catch (MailException e) {
                logger.warn(e.getMessage());
            }
            logger.debug("sent email to " + StringUtils.collectionToCommaDelimitedString(bccAddresses));
            bccAddresses.clear();
        }
    }
}

From source file:org.callistasoftware.netcare.core.spi.impl.EmailNotificationServiceImpl.java

private void doSendEmail(final String message, final String subject, final String toAddress) {
    log.info("Delivering email message '{}' to {}", subject, toAddress);

    final SimpleMailMessage smm = new SimpleMailMessage();
    smm.setTo(toAddress);/*from www . j a  va  2s.  co  m*/
    smm.setSubject(subject);
    smm.setText(message);

    try {
        this.mailSender.send(smm);
    } catch (final MailException e) {
        log.warn("Could not deliver email message. Reason: {}", e.getMessage());
    }
}

From source file:eu.supersede.fe.mail.SupersedeMailSender.java

/**
 * Send an email with the given subject and the given text to the given recipients.
 * @param subject//w w w . ja  v  a  2s.com
 * @param text
 * @param to
 */
public void sendEmail(String subject, String text, String... recipients) {
    if (javaMailSender != null) {
        try {
            MimeMessage message = javaMailSender.createMimeMessage();
            MimeMessageHelper helper;
            // SSL Certificate.
            helper = new MimeMessageHelper(message, true);
            helper.setSubject(subject);
            helper.setTo(recipients);
            helper.setText(text, true);
            javaMailSender.send(message);
        } catch (MailException ex) {
            log.error("Exception while send an email: " + ex.getMessage());
            ex.printStackTrace();
        } catch (MessagingException ex) {
            log.error("Exception while send an email: " + ex.getMessage());
            ex.printStackTrace();
        }
    } else {
        log.error("Java mail not configured");
    }
}

From source file:ru.retbansk.utils.scheduled.impl.ReplyManagerSimpleImpl.java

/**
 * Send an error email of a not valid day report.
 * // w ww  .ja v a 2s. com
 * @see org.springframework.mail.SimpleMailMessage
 * @see org.springframework.mail.javamail.JavaMailSenderImpl
 * @param dayReport I used DayReport as a parameter to know whom to send
 */
public void sendError(DayReport dayReport) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(dayReport.getPersonId());
    msg.setReplyTo(dayReport.getPersonId());
    msg.setFrom(user);
    msg.setSubject("RE: " + (dayReport.getSubject() == null ? "" : dayReport.getSubject()));
    msg.setText("This is an automated email. Do not reply.\n"
            + "No valid reports were detected. Check your report.\nExample of valid reports:\n"
            + "helping Google with Android, in process, 7\nmain job/ in process/1\nnothing actually. done. 3\n");

    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:ru.retbansk.utils.scheduled.impl.ReplyManagerSimpleImpl.java

/**
 * Send a confirmation email of a valid day report.
 * Includes xml readable string of it./*from  w  ww  .java2s.c o m*/
 * @see org.springframework.mail.SimpleMailMessage
 * @see org.springframework.mail.javamail.JavaMailSenderImpl
 */
@Override
public void placeReply(Reply reply) throws Exception {

    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(reply.getEmailAddress());
    msg.setReplyTo(reply.getEmailAddress());
    msg.setFrom(user);
    msg.setSubject("RE: " + (reply.getSubject() == null ? "" : reply.getSubject()));
    msg.setText("This is an automated email. Do not reply.\n" + "Your day report is recieved and saved ."
            + " You are allowed to make modifications till 23:59 GMT+3."
            + " Just send new report, the old one will be deleted.\n" + "Converted report look like:\n"
            + reply.getXml());

    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:org.musicrecital.service.MailEngine.java

/**
 * Send a simple message with pre-populated values.
 * @param msg the message to send/* www. j a  va2 s.c om*/
 * @throws org.springframework.mail.MailException when SMTP server is down
 */
public void send(SimpleMailMessage msg) throws MailException {
    try {
        mailSender.send(msg);
    } catch (MailException ex) {
        log.error(ex.getMessage());
        throw ex;
    }
}

From source file:com.miserablemind.butter.domain.service.email.EmailService.java

/**
 * Sends a plain text message. Uses {@link EmailMessage#getPlainTextBody()}
 *
 * @param emailMessage prepared message object to be sent. Usually prepared by {@link EmailManager}
 *///from w w  w.j a va  2 s.  c om
public void sendTextMail(EmailMessage emailMessage) {

    SimpleMailMessage textMessage = new SimpleMailMessage();

    textMessage.setFrom(emailMessage.getFromAddress().getAddress());
    textMessage.setTo(emailMessage.getToEmail());
    textMessage.setSubject(emailMessage.getSubject());
    textMessage.setText(emailMessage.getPlainTextBody());

    try {
        this.mailSender.send(textMessage);
    } catch (MailException e) {
        logger.error("Email Service Exception Send Text Mail: " + e.getMessage(), e);
    }
}