AWS SNS OTP 邮件

3
我正在使用Amazon SNS发送OTP消息以实现用户登录。 我能够像这里建议的一样发送文本消息。对于电子邮件通知,我也想采用类似的方法。 但是对于电子邮件通知,似乎必须在SNS中创建一个主题并为应用程序中注册的每个电子邮件ID创建一个订阅者。
是否可以像文本消息一样动态地向邮件ID发送电子邮件而不创建主题和订阅者? 如果不能,请建议一种根据登录的用户动态设置电子邮件ID的方法。
文本消息代码:
 public static void main(String[] args) {
    AmazonSNSClient snsClient = new AmazonSNSClient();
    String message = "My SMS message";
    String phoneNumber = "+1XXX5550100";
    Map<String, MessageAttributeValue> smsAttributes = 
            new HashMap<String, MessageAttributeValue>();
    //<set SMS attributes>
    sendSMSMessage(snsClient, message, phoneNumber, smsAttributes);
 }
 public static void sendSMSMessage(AmazonSNSClient snsClient, String message, 
    String phoneNumber, Map<String, MessageAttributeValue> smsAttributes) {
    PublishResult result = snsClient.publish(new PublishRequest()
                    .withMessage(message)
                    .withPhoneNumber(phoneNumber)
                    .withMessageAttributes(smsAttributes));
    System.out.println(result); // Prints the message ID.
 }
1个回答

4

正确。

Amazon SNS 通常使用发布/订阅模式传递消息。

唯一的例外是能够向特定接收者发送短信消息。

如果您想要向单个接收者发送电子邮件,则需要使用自己的 SMTP 服务器,或使用 Amazon 简单电子邮件服务(Amazon SES)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接