List of usage examples for com.amazonaws.services.simpleemail.model SendRawEmailResult getMessageId
public String getMessageId()
The unique message identifier returned from the SendRawEmail
action.
From source file:com.hiveTown.util.AmazonSESUtil.java
License:Open Source License
public String sendRawEmail(String[] toEmail, String fromAddress, MimeMessage mimeMessage) { try {/*from w w w . ja v a 2s . c o m*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); mimeMessage.writeTo(outputStream); RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray())); // Assemble the email. SendRawEmailRequest request = new SendRawEmailRequest().withSource(fromAddress) .withDestinations(toEmail).withRawMessage(rawMessage); // Send the email. SendRawEmailResult r = this.getClient().sendRawEmail(request); LOGGER.info(r.toString()); return r.getMessageId(); } catch (Exception ex) { LOGGER.error(ex.toString()); } return null; }
From source file:com.irurueta.server.commons.email.AWSMailSender.java
License:Apache License
/** * Method to send a text email with attachments or HTML emails with * attachments (inline or not)./*from w w w . j a v a2s. co m*/ * @param m email message to be sent. * @return id of message that has been sent. * @throws MailNotSentException if mail couldn't be sent. */ private String sendRawEmail(EmailMessage<MimeMessage> m) throws MailNotSentException { String messageId; long currentTimestamp = System.currentTimeMillis(); prepareClient(); if (!mEnabled) { //don't send message if not enabled return null; } try { synchronized (this) { //prevents throttling and excessive memory usage checkQuota(currentTimestamp); //if no subject, set to empty string to avoid errors if (m.getSubject() == null) { m.setSubject(""); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //convert message into mime multi part and write it to output //stream into memory Session session = Session.getInstance(new Properties()); MimeMessage mimeMessage = new MimeMessage(session); if (m.getSubject() != null) { mimeMessage.setSubject(m.getSubject(), "utf-8"); } m.buildContent(mimeMessage); mimeMessage.writeTo(outputStream); //m.buildMultipart().writeTo(outputStream); RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray())); SendRawEmailRequest rawRequest = new SendRawEmailRequest(rawMessage); rawRequest.setDestinations(m.getTo()); rawRequest.setSource(mMailFromAddress); SendRawEmailResult result = mClient.sendRawEmail(rawRequest); messageId = result.getMessageId(); //update timestamp of last sent email mLastSentMailTimestamp = System.currentTimeMillis(); //wait to avoid throwttling exceptions to avoid making any //further requests this.wait(mWaitIntervalMillis); } } catch (Throwable t) { throw new MailNotSentException(t); } return messageId; }
From source file:org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceJavaMailSender.java
License:Apache License
@SuppressWarnings("OverloadedVarargsMethod") @Override/*from w w w . ja v a 2s . c om*/ public void send(MimeMessage... mimeMessages) throws MailException { Map<Object, Exception> failedMessages = new HashMap<>(); for (MimeMessage mimeMessage : mimeMessages) { try { RawMessage rm = createRawMessage(mimeMessage); SendRawEmailResult sendRawEmailResult = getEmailService().sendRawEmail(new SendRawEmailRequest(rm)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Message with id: {0} successfully send", sendRawEmailResult.getMessageId()); } } catch (Exception e) { //Ignore Exception because we are collecting and throwing all if any //noinspection ThrowableResultOfMethodCallIgnored failedMessages.put(mimeMessage, e); } } if (!failedMessages.isEmpty()) { throw new MailSendException(failedMessages); } }