繁体   English   中英

AWS SNS OTP 电子邮件

[英]AWS SNS OTP emails

我正在使用 Amazon SNS 为用户登录发送 OTP 消息。 我可以按照此处的建议发送短信。 对于 email 通知,我也想使用类似的方法。 但是对于 email 通知,必须在 SNS 中创建一个主题,并且必须为应用程序中注册的每个 email id 创建一个订阅者。

在不创建主题和订阅者的情况下,是否不能像发送文本消息那样动态地将 email 发送到 mail-id? 如果不是,请建议一种根据登录用户动态设置 email 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.
 }

正确的。

Amazon SNS 通常对消息使用公共/订阅 model。

一个例外是向特定收件人发送 SMS 消息的能力。

如果您希望将 email 发送给单个收件人,则需要使用您自己的 SMTP 服务器,或使用 Amazon Simple Email 服务 ( Amazon SES )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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