简体   繁体   中英

How to put Label in email using AWS SES?

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 = "sender@example.com";
  static final String TO = "recipient@example.com";
  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:

sender@example.com

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 sender@example.com, you can use sender+myLabel@example.com 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 "sender+MyLabel@example.com", email gets sent as:

sender+MyLabel@example.com

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

I added label to my email by replacing my FROM variable's value from "sender@example.com" to "myLabel< sender@example.com>"

static final String FROM = "myLabel< sender@example.com>";

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM