1
votes

The document says that after sending an email, no matter it was successful or not, SES will return a response to the sender, includeing message ID and an error if it wasn't sent successfully. enter image description here https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-concepts-process.html

I am wondering how to get this response?

I am using SMTP and JavaMail to send emails, like: transport.sendMessage(msg, msg.getAllRecipients());

The sendMessage method doesn't return anything. So how can I get the response?

Thanks in advance!

Update:

In https://forums.aws.amazon.com/thread.jspa?messageID=363239, it is said that

SMTP returns the message ID appended to the OK response to the DATA command. For example: 250 Ok 0000aaaaccccaaaacccc-ccccaacc-aaaa-cccc-aaaa-acccccaaaaae-000000

Could anyone teach me how to extract the message ID from the OK response?

3

3 Answers

1
votes

At best you can register a TransportListener with Transport, this listener will be called with TransportEvent. This TransportListener is called every time Transport object emits an events like MESSAGE_DELIVERED, MESSAGE_NOT_DELIVERED, MESSAGE_PARTIALLY_DELIVERED.

You can do something like this -

// Create a transport.
Transport transport = session.getTransport();

//Register your event listener
//This TransportListener is called every time Transport object emits an events like `MESSAGE_DELIVERED`, `MESSAGE_NOT_DELIVERED`, `MESSAGE_PARTIALLY_DELIVERED`.
transport.addTransportListener(new TransportListener() {
    @Override
    public void messageDelivered(TransportEvent transportEvent) {
        System.out.println("From Message Delivered");
        System.out.println(transportEvent.getMessage());
    }

    @Override
    public void messageNotDelivered(TransportEvent transportEvent) {
        System.out.println("From Message Not Delivered");
        System.out.println(transportEvent.getMessage());
    }

    @Override
    public void messagePartiallyDelivered(TransportEvent transportEvent) {
        System.out.println("From Message Partially Delivered");
        System.out.println(transportEvent.getMessage());
    }
});
0
votes

I think that You can use configuration set for it. It only requires adding such header X-SES-CONFIGURATION-SET with the value of the title of Your configuration set.

Here is full link: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html

Later, when You configure the configuration set, You can set it up to push the delivery, bounce, etc notifications on SNS. Which You can subscribe to in Your application.

Here is a link: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-configuration-sets-in-email.html

And the link for the delivery object: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#delivery-object

0
votes

I fugured it out.

I should used getLastServerResponse() method of SMTPTransport class, such as

        String response = transport.getLastServerResponse();
        System.out.println("response: " + response);

The output will be like response: 250 Ok 0100017352b73695-a103f18d-f0a3-4a48-9d86-db1df264a3fe-000000