How to put Label in email using AWS SES?

751 Views Asked by At

I have used this code to send email using AWS SES:

package com.amazonaws.samples;

import java.io.IOException;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import com.amazonaws.services.simpleemail.model.Body;
import com.amazonaws.services.simpleemail.model.Content;
import com.amazonaws.services.simpleemail.model.Destination;
import com.amazonaws.services.simpleemail.model.Message;
import com.amazonaws.services.simpleemail.model.SendEmailRequest; 

public class AmazonSESSample {
  static final String FROM = "[email protected]";
  static final String TO = "[email protected]";
  static final String SUBJECT = "Amazon SES test (AWS SDK for Java)";
  static final String HTMLBODY = "Amazon SES test (AWS SDK for Java)";
  static final String TEXTBODY = "This email was sent through Amazon SES ";

  public static void main(String[] args) throws IOException {
    try {
      AmazonSimpleEmailService client = 
          AmazonSimpleEmailServiceClientBuilder.standard().withRegion(Regions.US_EAST_1).build()
      SendEmailRequest request = new SendEmailRequest()
          .withDestination(
              new Destination().withToAddresses(TO))
          .withMessage(new Message()
              .withBody(new Body()
                  .withHtml(new Content()
                      .withCharset("UTF-8").withData(HTMLBODY))
                  .withText(new Content()
                      .withCharset("UTF-8").withData(TEXTBODY)))
              .withSubject(new Content()
                  .withCharset("UTF-8").withData(SUBJECT)))
          .withSource(FROM)
      client.sendEmail(request);
      System.out.println("Email sent!");
    } catch (Exception ex) {
      System.out.println("The email was not sent. Error message: " 
          + ex.getMessage());
    }
  }
}

Now, my problem is I have to add a label to this email such that receiver sees:

MyLabel < @example.com>

instead of what receiver is currently seeing:

[email protected]

According to AWS SES's developer guide,

You can add labels to verified email addresses without performing additional verification steps. To add a label to an email address, add a plus sign (+) between the account name and the "at" sign (@), followed by a text label. For example, if you already verified [email protected], you can use [email protected] as the "From" or "Return-Path" address for your emails. You can use this feature to implement Variable Envelope Return Path (VERP). Then you can use VERP to detect and remove undeliverable email addresses from your mailing lists.

But, if I change FROM to "[email protected]", email gets sent as:

[email protected]

Eventhough, I have verified my FROM email address. Please help.

1

There are 1 best solutions below

0
On

I added label to my email by replacing my FROM variable's value from "[email protected]" to "myLabel< [email protected]>"

static final String FROM = "myLabel< [email protected]>";