英文:
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:
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:
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>";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论