如何使用AWS SES将Label放入电子邮件中?

问题描述

我已使用此代码通过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());
    }
  }
}

现在,我的问题是我必须在此电子邮件添加标签,以便收件人看到:

MyLabel

而不是接收者当前正在查看的内容

sender@example.com

根据AWS SES的开发人员指南

您可以将标签添加到已验证的电子邮件地址,而无需执行 其他验证步骤。要将标签添加到电子邮件地址,请添加 帐户名称和“ at”符号(@)之间的加号(+), 然后是文字标签。例如,如果您已经验证 sender@example.com,您可以将sender+myLabel@example.com用作 电子邮件的“发件人”或“返回路径”地址。你可以用这个 功能来实现可变信封返回路径(VERP)。然后你 可以使用VERP检测并删除无法发送的电子邮件地址 您的邮件列表。

但是,如果我将FROM更改为“ sender+MyLabel@example.com”,则电子邮件的发送方式为:

sender+MyLabel@example.com

不过,我已经验证了我的FROM电子邮件地址。请帮忙。

解决方法

我通过将我的FROM变量的值从“ sender@example.com”替换为“ myLabel ”来为电子邮件添加标签

静态最终字符串FROM =“ myLabel ”;