I am using AWS SDK for java to send emails. Following is my code -
public void sendMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
// Sending the email.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mimeMessage.writeTo(outputStream);
RawMessage rawMessage =
new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest =
new SendRawEmailRequest(rawMessage);
SendRawEmailResult result = client.sendRawEmail(rawEmailRequest);
log.info("Email sent!");
log.debug("Email sent with message id: {}",result.getMessageId());
}
Now I want to be able to check if my email was sent or not. I found some documentation stating that SES always returns a response along with the message id, if so how can I extract the response from the message id? If not, then what other ways are possible to get the response?
Try / catch. Do the error handling in the catch block.
public void sendMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
// Sending the email.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mimeMessage.writeTo(outputStream);
RawMessage rawMessage =
new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest =
new SendRawEmailRequest(rawMessage);
try {
SendRawEmailResult result = client.sendRawEmail(rawEmailRequest);
} catch (Exception e) {
// Handle error here
}
}
Looks to me like you're missing an await command.
I think it should look like this:
SendRawEmailResult result = await client.sendRawEmail(rawEmailRequest);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.