Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SES client builder instead constructor in AWSJavaMailTransport #2636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.mail.internet.MimeMessage;

import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.model.RawMessage;
import com.amazonaws.services.simpleemail.model.SendRawEmailRequest;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class AWSJavaMailTransport extends Transport {
public static final String AWS_SECRET_KEY_PROPERTY = "mail.aws.password";
public static final String AWS_ACCESS_KEY_PROPERTY = "mail.aws.user";

private AmazonSimpleEmailServiceClient emailService;
private AmazonSimpleEmailService emailService;
private final String accessKey;
private final String secretKey;
private final String httpsEndpoint;
Expand Down Expand Up @@ -308,7 +309,7 @@ private void sendEmail(Message m, SendRawEmailRequest req)
*/
@Override
protected boolean protocolConnect(String host, int port, String awsAccessKey,
String awsSecretKey) {
String awsSecretKey) {
if (isConnected())
throw new IllegalStateException("Already connected");

Expand All @@ -318,15 +319,18 @@ protected boolean protocolConnect(String host, int port, String awsAccessKey,
// - Environment Variables
// - Java System Properties
// - Instance profile credentials delivered through the Amazon EC2 metadata service
this.emailService = new AmazonSimpleEmailServiceClient();
this.emailService = AmazonSimpleEmailServiceClientBuilder.defaultClient();
}
awsAccessKey = this.accessKey;
awsSecretKey = this.secretKey;
}

if (this.emailService == null) {
// Use the supplied credentials.
this.emailService = new AmazonSimpleEmailServiceClient(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
this.emailService = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials(awsAccessKey, awsSecretKey))).build();
}

if (!isNullOrEmpty(host)) {
Expand All @@ -345,13 +349,13 @@ public void close() throws MessagingException {
}

/**
* <p>
* The unique message identifier ot the last message sent by <code>sendMessage</code>
* </p>
*
* @return The unique message identifier sent by the last
* <code>sendMessage</code> action.
*/
* <p>
* The unique message identifier ot the last message sent by <code>sendMessage</code>
* </p>
*
* @return The unique message identifier sent by the last
* <code>sendMessage</code> action.
*/
public String getLastMessageId() {
return lastMessageId;
}
Expand Down