【发布时间】: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