简体   繁体   English

AWS SNS OTP 电子邮件

[英]AWS SNS OTP emails

I am working on sending OTP messages for user login leveraging Amazon SNS.我正在使用 Amazon SNS 为用户登录发送 OTP 消息。 I am able to send Text message as suggesting here .我可以按照此处的建议发送短信。 For the email notification as well I would like to use a similar approach.对于 email 通知,我也想使用类似的方法。 But looks like for email notifications, a topic has to be created in SNS and a subscriber has to be created for each email id registered in the application.但是对于 email 通知,必须在 SNS 中创建一个主题,并且必须为应用程序中注册的每个 email id 创建一个订阅者。

Is it not possible to send email to mail-id dynamically as done for text messages without creating topics and subscribers?在不创建主题和订阅者的情况下,是否不能像发送文本消息那样动态地将 email 发送到 mail-id? If not please suggest a way to set email id dynamically based on the user logged in.如果不是,请建议一种根据登录用户动态设置 email id 的方法。

Code for Text Messaging:短信代码:

 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.
 }

Correct.正确的。

Amazon SNS normally uses a Public/Subscribe model for messages. Amazon SNS 通常对消息使用公共/订阅 model。

The one exception is the ability to send an SMS message to a specific recipient.一个例外是向特定收件人发送 SMS 消息的能力。

If you wish to send an email to a single recipient, you will need to use your own SMTP server , or use Amazon Simple Email Service ( Amazon SES ).如果您希望将 email 发送给单个收件人,则需要使用您自己的 SMTP 服务器,或使用 Amazon Simple Email 服务 ( Amazon SES )。

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

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