Search in sources :

Example 1 with MessageRequest

use of software.amazon.awssdk.services.pinpoint.model.MessageRequest in project aws-doc-sdk-examples by awsdocs.

the class SendEmailMessage method sendEmail.

// snippet-start:[pinpoint.java2.send_email.main]
public static void sendEmail(PinpointClient pinpoint, String subject, String appId, String senderAddress, String toAddress) {
    try {
        Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
        AddressConfiguration configuration = AddressConfiguration.builder().channelType(ChannelType.EMAIL).build();
        addressMap.put(toAddress, configuration);
        SimpleEmailPart emailPart = SimpleEmailPart.builder().data(htmlBody).charset(charset).build();
        SimpleEmailPart subjectPart = SimpleEmailPart.builder().data(subject).charset(charset).build();
        SimpleEmail simpleEmail = SimpleEmail.builder().htmlPart(emailPart).subject(subjectPart).build();
        EmailMessage emailMessage = EmailMessage.builder().body(htmlBody).fromAddress(senderAddress).simpleEmail(simpleEmail).build();
        DirectMessageConfiguration directMessageConfiguration = DirectMessageConfiguration.builder().emailMessage(emailMessage).build();
        MessageRequest messageRequest = MessageRequest.builder().addresses(addressMap).messageConfiguration(directMessageConfiguration).build();
        SendMessagesRequest messagesRequest = SendMessagesRequest.builder().applicationId(appId).messageRequest(messageRequest).build();
        pinpoint.sendMessages(messagesRequest);
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : EmailMessage(software.amazon.awssdk.services.pinpoint.model.EmailMessage) MessageRequest(software.amazon.awssdk.services.pinpoint.model.MessageRequest) SendMessagesRequest(software.amazon.awssdk.services.pinpoint.model.SendMessagesRequest) HashMap(java.util.HashMap) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) SimpleEmailPart(software.amazon.awssdk.services.pinpoint.model.SimpleEmailPart) DirectMessageConfiguration(software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration) AddressConfiguration(software.amazon.awssdk.services.pinpoint.model.AddressConfiguration) SimpleEmail(software.amazon.awssdk.services.pinpoint.model.SimpleEmail)

Example 2 with MessageRequest

use of software.amazon.awssdk.services.pinpoint.model.MessageRequest in project aws-doc-sdk-examples by awsdocs.

the class SendMessage method sendSMSMessage.

// snippet-start:[pinpoint.java2.sendmsg.main]
public static void sendSMSMessage(PinpointClient pinpoint, String message, String appId, String originationNumber, String destinationNumber) {
    try {
        Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
        AddressConfiguration addConfig = AddressConfiguration.builder().channelType(ChannelType.SMS).build();
        addressMap.put(destinationNumber, addConfig);
        SMSMessage smsMessage = SMSMessage.builder().body(message).messageType(messageType).originationNumber(originationNumber).senderId(senderId).keyword(registeredKeyword).build();
        // Create a DirectMessageConfiguration object
        DirectMessageConfiguration direct = DirectMessageConfiguration.builder().smsMessage(smsMessage).build();
        MessageRequest msgReq = MessageRequest.builder().addresses(addressMap).messageConfiguration(direct).build();
        // create a  SendMessagesRequest object
        SendMessagesRequest request = SendMessagesRequest.builder().applicationId(appId).messageRequest(msgReq).build();
        SendMessagesResponse response = pinpoint.sendMessages(request);
        MessageResponse msg1 = response.messageResponse();
        Map map1 = msg1.result();
        // Write out the result of sendMessage
        map1.forEach((k, v) -> System.out.println((k + ":" + v)));
    } catch (PinpointException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SendMessagesResponse(software.amazon.awssdk.services.pinpoint.model.SendMessagesResponse) MessageRequest(software.amazon.awssdk.services.pinpoint.model.MessageRequest) SMSMessage(software.amazon.awssdk.services.pinpoint.model.SMSMessage) SendMessagesRequest(software.amazon.awssdk.services.pinpoint.model.SendMessagesRequest) HashMap(java.util.HashMap) MessageResponse(software.amazon.awssdk.services.pinpoint.model.MessageResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) DirectMessageConfiguration(software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration) AddressConfiguration(software.amazon.awssdk.services.pinpoint.model.AddressConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 AddressConfiguration (software.amazon.awssdk.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration)2 MessageRequest (software.amazon.awssdk.services.pinpoint.model.MessageRequest)2 PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)2 SendMessagesRequest (software.amazon.awssdk.services.pinpoint.model.SendMessagesRequest)2 Map (java.util.Map)1 EmailMessage (software.amazon.awssdk.services.pinpoint.model.EmailMessage)1 MessageResponse (software.amazon.awssdk.services.pinpoint.model.MessageResponse)1 SMSMessage (software.amazon.awssdk.services.pinpoint.model.SMSMessage)1 SendMessagesResponse (software.amazon.awssdk.services.pinpoint.model.SendMessagesResponse)1 SimpleEmail (software.amazon.awssdk.services.pinpoint.model.SimpleEmail)1 SimpleEmailPart (software.amazon.awssdk.services.pinpoint.model.SimpleEmailPart)1