Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send when no to: address supplied. #1173

Closed
buckett opened this issue Jul 5, 2024 · 1 comment · Fixed by #1174
Closed

Unable to send when no to: address supplied. #1173

buckett opened this issue Jul 5, 2024 · 1 comment · Fixed by #1174

Comments

@buckett
Copy link
Contributor

buckett commented Jul 5, 2024

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 <sender@other.test>");
    template.setSubject("Subject");
    template.setBody("Nothing to see here");

    SimpleMailMessage message = new SimpleMailMessage(template);
    message.setBcc("User 1 <user1@server.test>", "User 2 <user2@server.test>");
    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
Copy link
Contributor Author

buckett commented Jul 5, 2024

The stack trace we were seeing:

java.lang.NullPointerException: null
    at java.util.Objects.requireNonNull
    at java.util.Arrays$ArrayList.<init>
    at java.util.Arrays.asList
    at software.amazon.awssdk.services.ses.model.Destination$BuilderImpl.toAddresses(Destination.java:391)
    at io.awspring.cloud.ses.SimpleEmailServiceMailSender.prepareMessage(SimpleEmailServiceMailSender.java:114)
    at io.awspring.cloud.ses.SimpleEmailServiceMailSender.send(SimpleEmailServiceMailSender.java:84)
    at io.awspring.cloud.ses.SimpleEmailServiceMailSender.send(SimpleEmailServiceMailSender.java:74)
    [..snipped..]

@buckett buckett changed the title Unable to send Unable to send when no to: address supplied. Jul 5, 2024
buckett added a commit to buckett/spring-cloud-aws that referenced this issue Jul 5, 2024
It's valid to send an email message through SES that doesn't have a to address (just cc or bcc).

Fixes: awspring#1173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant