如何在使用AWS SES时在电子邮件中添加标签?

huangapple go评论119阅读模式
英文:

How to put Label in email using AWS SES?

问题

以下是使用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());
    }
  }
}

根据AWS SES的开发人员指南,您可以在验证的电子邮件地址上添加标签,而无需执行其他验证步骤。要向电子邮件地址添加标签,在帐户名称和“at”符号(@)之间添加加号(+),然后是文本标签。例如,如果您已经验证了sender@example.com,您可以在您的电子邮件的“From”或“Return-Path”地址中使用sender+myLabel@example.com。您可以使用此功能来实现可变信封返回路径(VERP)。然后,您可以使用VERP从邮件列表中检测并删除不可投递的电子邮件地址。

但是,如果我将FROM更改为"sender+MyLabel@example.com",电子邮件将以以下方式发送:

sender+MyLabel@example.com

尽管我已经验证了我的FROM电子邮件地址。请帮忙解决。

英文:

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.

答案1

得分: 3

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

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

英文:

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>";

huangapple
  • 本文由 发表于 2020年9月22日 14:49:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/64004432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定