spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Unable to send when no to: address supplied.

Open buckett opened this issue 7 months ago • 1 comments

Type: Bug

Component: SES

Describe the bug Unable to send an email that doesn't have an TO: address.

We were attempting to send an email that just has lots of BCCs (no TO: address) and this worked with JavaMail, but when we switched to using the Spring Cloud AWS integration it started failing. According to the documentation on SES it states:

The message must include at least one recipient email address. The recipient address can be a To: address, a CC: address, or a BCC: address.

Sample

    SimpleMailMessage template = new SimpleMailMessage();
    template.setFrom("Sender <[email protected]>");
    template.setSubject("Subject");
    template.setBody("Nothing to see here");

    SimpleMailMessage message = new SimpleMailMessage(template);
    message.setBcc("User 1 <[email protected]>", "User 2 <[email protected]>");
    mailsender.send(message).

Workaround

To workaround this you can set the to address to be new String[]{} which is the same as passing nothing. This ends up setting the to address to not be null, but doesn't cause problems with the SES implementation.

    message.setTo();

Passing null doesn't work as this creates an array with one item (of value null) which then fails because it's not a valid email.

buckett avatar Jul 05 '24 08:07 buckett