Example usage for javax.mail MessagingException getMessage

List of usage examples for javax.mail MessagingException getMessage

Introduction

In this page you can find the example usage for javax.mail MessagingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.openadaptor.auxil.connector.smtp.SMTPWriteConnector.java

/**
 * Creates and sends email containing the data. The body of the message is a concatentation of
 * calls to {@link #toString()} on each element in the data array.
 *
 * @param data an array of objects to be processed.
 * @return result string confirming that the email was sucessfully sent.
 * @throws OAException//from  ww  w .  j a v  a  2  s . c  om
 */
public Object deliver(Object[] data) throws OAException {
    String result = null;
    String body = "";

    int size = data.length;
    for (int recordIndex = 0; recordIndex < size; recordIndex++) {
        Object record = data[recordIndex];
        try {
            if (record != null) {
                body += record.toString();
                smtpConnection.generateMessageBody(body);
                smtpConnection.send();
            } else {
                throw new ProcessingException("Malformed data for smtp write connector - record has null value",
                        this);
            }
        } catch (MessagingException me) {
            throw new ConnectionException(me.getMessage(), me, this);
        }
    }

    result = "Email message sent successfully, contained " + size + " records";
    log.info(result);
    return result;

}

From source file:com.cws.esolutions.core.utils.EmailUtilsTest.java

@Test
public void sendEmailMessage() {
    EmailMessage message = new EmailMessage();
    message.setIsAlert(false);/*ww  w  . ja  v  a2s  .c  o  m*/
    message.setMessageSubject("Test Message");
    message.setMessageBCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageTo(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setEmailAddr(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageBody("This is a test message");

    try {
        EmailUtils.sendEmailMessage(EmailUtilsTest.bean.getConfigData().getMailConfig(), message, false);
    } catch (MessagingException mx) {
        Assert.fail(mx.getMessage());
    }
}

From source file:com.cws.esolutions.core.utils.EmailUtilsTest.java

@Test
public void sendEmailMessageAsSMS() {
    EmailMessage message = new EmailMessage();
    message.setIsAlert(false);/*from  w  w w  .j a va2s  .co m*/
    message.setMessageSubject("Test Message");
    message.setMessageBCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageTo(new ArrayList<String>(Arrays.asList("7163415669@vmobl.com")));
    message.setEmailAddr(new ArrayList<String>(Arrays.asList("cws-khuntly")));
    message.setMessageBody("This is a test message");

    try {
        EmailUtils.sendEmailMessage(EmailUtilsTest.bean.getConfigData().getMailConfig(), message, false);
    } catch (MessagingException mx) {
        Assert.fail(mx.getMessage());
    }
}

From source file:com.hs.mail.smtp.spool.SmtpMessageConsumer.java

private void dsnNotify(SmtpMessage message) {
    if (!message.isNotificationMessage()) {
        try {//  w  w  w  .j a  v a2s  .  co m
            // Bounce message to the reverse-path
            DeliveryStatusNotifier.dsnNotify(null, message.getFrom(), message.getMimeMessage(),
                    message.getErrorMessage());
        } catch (MessagingException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:net.jetrix.mail.MailSessionManager.java

/**
 * Check if the mail session is working properly.
 */// ww w.  j  av a  2  s .c  o  m
public boolean checkSession() {
    boolean check = false;

    if (session != null) {
        try {
            Transport transport = session.getTransport();
            transport.connect();
            transport.close();

            check = true;
        } catch (MessagingException e) {
            log.warning("Unable to validate the mail session (" + e.getMessage() + ")");
        }
    }

    return check;
}

From source file:com.cws.esolutions.core.utils.EmailUtilsTest.java

@Test
public void sendEmailMessageWithAttachment() {
    try {/* w w w .j  av  a2  s.  c  o m*/
        Map<String, InputStream> attachments = new HashMap<String, InputStream>() {
            private static final long serialVersionUID = 1L;

            {
                put("myFile", new FileInputStream(FileUtils.getFile("C:/temp", "myFile")));
            }
        };

        EmailMessage message = new EmailMessage();
        message.setIsAlert(false);
        message.setMessageSubject("Test Message");
        message.setMessageBCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
        message.setMessageCC(new ArrayList<String>(Arrays.asList("cws-khuntly")));
        message.setMessageTo(new ArrayList<String>(Arrays.asList("cws-khuntly")));
        message.setEmailAddr(new ArrayList<String>(Arrays.asList("cws-khuntly")));
        message.setMessageBody("This is a test message");
        message.setMessageAttachments(attachments);

        EmailUtils.sendEmailMessage(EmailUtilsTest.bean.getConfigData().getMailConfig(), message, false);
    } catch (MessagingException mx) {
        Assert.fail(mx.getMessage());
    } catch (FileNotFoundException fnfx) {
        Assert.fail(fnfx.getMessage());
    }
}

From source file:gwtupload.sendmailsample.server.SendMailSampleServlet.java

@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles)
        throws UploadActionException {
    try {/*from  ww w .  j  a  v  a2 s. co m*/
        String from = null, to = null, subject = "", body = "";
        // create a new multipart content
        MimeMultipart multiPart = new MimeMultipart();
        for (FileItem item : sessionFiles) {
            if (item.isFormField()) {
                if ("from".equals(item.getFieldName()))
                    from = item.getString();
                if ("to".equals(item.getFieldName()))
                    to = item.getString();
                if ("subject".equals(item.getFieldName()))
                    subject = item.getString();
                if ("body".equals(item.getFieldName()))
                    body = item.getString();
            } else {
                // add the file part to multipart content
                MimeBodyPart part = new MimeBodyPart();
                part.setFileName(item.getName());
                part.setDataHandler(
                        new DataHandler(new ByteArrayDataSource(item.get(), item.getContentType())));
                multiPart.addBodyPart(part);
            }
        }

        // add the text part to multipart content
        MimeBodyPart txtPart = new MimeBodyPart();
        txtPart.setContent(body, "text/plain");
        multiPart.addBodyPart(txtPart);

        // configure smtp server
        Properties props = System.getProperties();
        props.put("mail.smtp.host", SMTP_SERVER);
        // create a new mail session and the mime message
        MimeMessage mime = new MimeMessage(Session.getInstance(props));
        mime.setText(body);
        mime.setContent(multiPart);
        mime.setSubject(subject);
        mime.setFrom(new InternetAddress(from));
        for (String rcpt : to.split("[\\s;,]+"))
            mime.addRecipient(Message.RecipientType.TO, new InternetAddress(rcpt));
        // send the message
        Transport.send(mime);
    } catch (MessagingException e) {
        throw new UploadActionException(e.getMessage());
    }
    return "Your mail has been sent successfuly.";
}

From source file:de.micromata.genome.gwiki.model.GWikiStandardEmailProvider.java

@Override
public void sendEmail(Map<String, String> ctx) {
    try {/*  w  w  w .j ava  2 s  .  c o m*/
        if (ctx.containsKey("MAILTEMPLATE") == true) {
            evaluateMailTemplate(ctx.get("MAILTEMPLATE"), ctx);
        }
        sendEmailImpl(ctx);
        GLog.note(GWikiLogCategory.Wiki, "Send email: " + ctx.get(TO),
                new LogAttribute(GenomeAttributeType.EmailMessage, ctx.toString()));
    } catch (MessagingException ex) {
        ctx.put(SENDEMAILFAILED, ex.getMessage());
        GLog.warn(GWikiLogCategory.Wiki, "Fail to send email: " + ctx.get(TO) + ": " + ex.getMessage(),
                new LogExceptionAttribute(ex),
                new LogAttribute(GenomeAttributeType.EmailMessage, ctx.toString()));
    }
}

From source file:org.mobicents.servlet.restcomm.email.EmailService.java

EmailResponse send(final Mail mail) {
    try {// ww  w.j ava 2  s .c o  m
        InternetAddress from;
        if (mail.from() != null || !mail.from().equalsIgnoreCase("")) {
            from = new InternetAddress(mail.from());
        } else {
            from = new InternetAddress(user);
        }
        final InternetAddress to = new InternetAddress(mail.to());
        final MimeMessage email = new MimeMessage(session);
        email.setFrom(from);
        email.addRecipient(Message.RecipientType.TO, to);
        email.setSubject(mail.subject());
        email.setText(mail.body());
        email.addRecipients(Message.RecipientType.CC, InternetAddress.parse(mail.cc(), false));
        email.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(mail.bcc(), false));
        Transport.send(email);
        return new EmailResponse(mail);
    } catch (final MessagingException exception) {
        logger.error(exception.getMessage(), exception);
        return new EmailResponse(exception, exception.getMessage());
    }
}

From source file:com.spartasystems.holdmail.smtp.OutgoingMailSender.java

public void redirectMessage(String recipient, String rawBody) {

    // TODO: this is a crude first pass at bouncing a mail and probably needs to be a little more sophisticated

    try {/* w  w  w  .jav a 2s.  c  o  m*/

        Session session = getMailSession();
        Message message = initializeMimeMessage(rawBody, session);

        // wipe out ALL exisitng recipients
        message.setRecipients(Message.RecipientType.TO, new Address[] {});
        message.setRecipients(Message.RecipientType.CC, new Address[] {});
        message.setRecipients(Message.RecipientType.BCC, new Address[] {});

        // and set the new recipient
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));

        InternetAddress[] parsedFrom = InternetAddress.parse(getSenderFrom());
        if (parsedFrom.length > 0) {
            message.setFrom(parsedFrom[0]);
            logger.info("Outgoing mail will have From: " + parsedFrom[0].getAddress());
        }

        sendMessage(message);

        logger.info("Outgoing mail forwarded to " + recipient);

    } catch (MessagingException e) {
        throw new HoldMailException("couldn't send mail: " + e.getMessage(), e);
    }

}