public MimeMessage buildMimeMessage(PlainTextMail data) { requireNonNull(data, "data"); MimeMailMessage builder = mimeBuilder(); builder.setFrom(config.fromAddress().get()); builder.setTo(data.getRecipient().get()); builder.setSubject(data.getSubject()); builder.setText(data.getContent()); return builder.getMimeMessage(); }
public void forward(Address[] forwardTo, SimpleMailMessage... simpleMessages) throws MailException { List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(simpleMessages.length); for (SimpleMailMessage simpleMessage : simpleMessages) { MimeMailMessage message = new MimeMailMessage(createMimeMessage()); simpleMessage.copyTo(message); mimeMessages.add(message.getMimeMessage()); } doForward(forwardTo, mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages); }
@Override public void send(final SimpleMailMessage[] simpleMessages) throws MailException { List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(simpleMessages.length); for (SimpleMailMessage simpleMessage : simpleMessages) { MimeMailMessage message = new MimeMailMessage(createMimeMessage()); simpleMessage.copyTo(message); mimeMessages.add(message.getMimeMessage()); } _doSend(mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages); }
/** * Construct and a send mime email message from an Attachment Mail Message. * * @param message the Attachement Mail Message * @throws MessagingException */ @Override public void sendEmail(AttachmentMailMessage message) throws MessagingException { // Construct a mime message from the Attachment Mail Message MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeBodyPart body = new MimeBodyPart(); body.setText(message.getMessage()); MimeBodyPart attachment = new MimeBodyPart(); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(body); ByteArrayDataSource ds = new ByteArrayDataSource(message.getContent(), message.getType()); attachment.setDataHandler(new DataHandler(ds)); attachment.setFileName(message.getFileName()); multipart.addBodyPart(attachment); mimeMessage.setContent(multipart); MimeMailMessage mmm = new MimeMailMessage(mimeMessage); mmm.setTo( (String[])message.getToAddresses().toArray(new String[message.getToAddresses().size()]) ); mmm.setBcc( (String[])message.getBccAddresses().toArray(new String[message.getBccAddresses().size()]) ); mmm.setCc( (String[])message.getCcAddresses().toArray(new String[message.getCcAddresses().size()]) ); mmm.setSubject(message.getSubject()); mmm.setFrom(message.getFromAddress()); try { if ( LOG.isDebugEnabled() ) { LOG.debug( "sendEmail() - Sending message: " + mmm.toString() ); } mailSender.send(mmm.getMimeMessage()); } catch (Exception e) { LOG.error("sendEmail() - Error sending email.", e); throw new RuntimeException(e); } }
/** * <p>buildMimeMessage</p> * * @param msg a {@link org.opennms.netmgt.config.javamail.SendmailMessage} object. * @return a {@link org.springframework.mail.javamail.MimeMailMessage} object. */ public MimeMailMessage buildMimeMessage(SendmailMessage msg) { //no need to set the same object again if (m_config.getSendmailMessage() != msg) { m_config.setSendmailMessage(msg); } MimeMailMessage mimeMsg = new MimeMailMessage(new MimeMessage(m_session)); mimeMsg.setFrom(m_config.getSendmailMessage().getFrom()); mimeMsg.setTo(m_config.getSendmailMessage().getTo()); mimeMsg.setSubject(m_config.getSendmailMessage().getSubject()); return mimeMsg; }
@Override public void send(SimpleMailMessage simpleMessage) throws MailException { MimeMailMessage message = new MimeMailMessage(createMimeMessage()); simpleMessage.copyTo(message); final Properties javaMailProperties = getJavaMailProperties(); javaMailProperties.setProperty("mailContent", simpleMessage.getText()); }
private MimeMailMessage mimeBuilder() { MimeMessageHelper helper = new MimeMessageHelper( mailClient.createMimeMessage(), StandardCharsets.UTF_8.name()); return new MimeMailMessage(helper); }
/** * <p>setMessage</p> * * @param message a {@link org.springframework.mail.javamail.MimeMailMessage} object. */ public void setMessage(MimeMailMessage message) { m_message = message; }
/** * <p>getMessage</p> * * @return a {@link org.springframework.mail.javamail.MimeMailMessage} object. */ public MimeMailMessage getMessage() { return m_message; }