By using AWS re:Post, you agree to the Terms of Use

Cannot send email from within JBoss on EC2: Could not convert socket to TLS


Hi, I'm running a java app in JBoss 6.4.0 in a red hat 8 EC2 instance. When my app tries to send an email via javax.mail I'm getting an error "Could not convert socket to TLS".

I then coded up the sample program and tried it. I ran it in my EC2 instance outside JBoss and it ran successfully. (The AmazonSESSample program can be found here:

Then I commented out the email code in my java app, and replaced it with the code in When I run my java app with the AmazonSESSample code in JBoss I get the same error: "Could not convert socket to TLS". So the AmazonSESSample works fine outside JBoss, and gives an error when running inside JBoss.

Here is the AmazonSESSample code in my app. Can somebody help me fix the "Could not convert socket to TLS" error?

Also I wasn't sure if I posted this in the right forum. Please suggest a better on if this one is not appropriate.

public class AmazonSESSample {

private static final Logger logger = LogManager.getFormatterLogger("AmazonSESSample");

// Replace with your "From" address.
// This address must be verified.
static final String FROM = "";
static final String FROMNAME = "Steve";

// Replace with a "To" address. If your account 
// is still in the sandbox, this address must be verified.
static final String TO = "";

// Replace smtp_username with your Amazon SES SMTP user name.
static final String SMTP_USERNAME = "thisIsNotActualghijikl";

// Replace smtp_password with your Amazon SES SMTP password.
static final String SMTP_PASSWORD = "abcdefThisIsNotActual";

// Amazon SES SMTP host name. This example uses the US West (Oregon) region.
// See
// for more information.
static final String HOST = ""; 

// The port you will connect to on the Amazon SES SMTP endpoint. 
static final int PORT = 587;

static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";

static final String BODY = String.join(
	    "<h1>Amazon SES SMTP Email Test</h1>",
	    "<p>This email was sent with Amazon SES using the ", 
	    "<a href=''>Javamail Package</a>",
	    " for <a href=''>Java</a>."

public int sendEmail(DisplayEmailMessage emailMessage) throws UnsupportedEncodingException, MessagingException {
	 // Create a Properties object to contain connection configuration information.
	Properties props = System.getProperties();
	props.put("mail.transport.protocol", "smtp");
	props.put("mail.smtp.port", PORT); 
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.auth", "true");

    // Create a Session object to represent a mail session with the specified properties. 
	Session session = Session.getDefaultInstance(props);

    // Create a message with the specified information. 
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(FROM, FROMNAME));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
    msg.setContent(BODY, "text/html");
    // Create a transport.
    Transport transport = session.getTransport();
    // Send the message.
    try {
        // Connect to Amazon SES using the SMTP username and password you specified above.
        transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
        // Send the email.
        transport.sendMessage(msg, msg.getAllRecipients());
        System.out.println("Email sent!");
    catch (Exception ex) {
        System.out.println("The email was not sent.");
        System.out.println("Error message: " + ex.getMessage());
    finally {
        // Close and terminate the connection.
    return 0;


1 Answer

If you aren't sure if your local trust store includes the root of SES's cert chain, try adding:

props.put("", "*");

To temporary accept all signers. If that fixes the issue you can import the SES root into the store.

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions