- AWS: Java S3 Lambda Handler
- AWS: Java Kinesis Lambda Handler
- AWS: Java S3 Upload
- AWS: Java Post to Kinesis Queue
- AWS: Send Simple Email Service
If you want to send an email using AWS’ Simple Mail then you need to do the following. This is a very basic example.
Import the following:
import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder; import com.amazonaws.services.simpleemail.model.Body; import com.amazonaws.services.simpleemail.model.Content; import com.amazonaws.services.simpleemail.model.Destination; import com.amazonaws.services.simpleemail.model.Message; import com.amazonaws.services.simpleemail.model.SendEmailRequest;
Setup Connection to AWS Simple Email Service
final AmazonSimpleEmailService simpleEmailService = AmazonSimpleEmailServiceClientBuilder.standard().withRegion(myRegion) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretKey))) .build();
Setup Email:
final SendEmailRequest request = new SendEmailRequest().withDestination(new Destination().withToAddresses(TO)).withSource(FROM) .withMessage(new Message().withSubject(new Content().withCharset("UTF-8").withData(SUBJECT)) .withBody(new Body().withText(new Content().withCharset("UTF-8").withData(BODY))));
Send Email:
simpleEmailService.sendEmail(request);