【问题标题】:AWS SNS OTP emailsAWS SNS OTP 电子邮件
【发布时间】:2021-04-02 16:40:28
【问题描述】:

我正在利用 Amazon SNS 为用户登录发送 OTP 消息。我可以发送短信作为建议here。对于电子邮件通知,我也想使用类似的方法。但是看起来对于电子邮件通知,必须在 SNS 中创建一个主题,并且必须为应用程序中注册的每个电子邮件 ID 创建一个订阅者。

在不创建主题和订阅者的情况下,是否不能像文本消息那样动态地向 mail-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.
 }

【问题讨论】:

    标签: amazon-web-services amazon-sns


    【解决方案1】:

    正确。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 2016-04-04
      • 2016-01-19
      • 1970-01-01
      • 2020-07-07
      • 2018-03-31
      相关资源
      最近更新 更多