Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tried to run you code for myself to see what would happen. First, I made sure I had <code>mail.jar</code> file available on the classpath. Second, I did a bit of necessary changes in order to be able to run the code without getting authentication errors. i.e, instead of:</p> <pre><code>props.put("mail.smtp.host", "smtp.exchangemails.com"); </code></pre> <p>I used:</p> <pre><code>props.put("mail.smtp.host", "smtp.gmail.com"); </code></pre> <p>and obviously, I had to provide my own username and password for this different host. </p> <p>You are right; The application worked well when was executed standalone. However, when I moved it to a <code>JBoss AS 7.0.0</code>, I encountered two different problems.</p> <p>Initially, I faced this error:</p> <pre><code>at javax.mail.Session.getDefaultInstance(Session.java:320) [mail-1.4.4.jar:1.4.4] at test.TestJavaMail.process(TestJavaMail.java:42) [classes:] </code></pre> <p>which after some googling and finding the solution given <a href="http://www.java.net/node/697528" rel="nofollow">here</a>, I could get rid of this error. i.e, I replaced this line:</p> <pre><code>Session session = Session.getDefaultInstance(props, auth); </code></pre> <p>with:</p> <pre><code>Session session = Session.getInstance(props, auth); </code></pre> <p>Then, I tried running the application again. This time, I received the below error:</p> <pre><code>java.lang.NoClassDefFoundError: javax/net/ssl/SSLPeerUnverifiedException com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900) com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638) javax.mail.Service.connect(Service.java:295) test.TestJavaMail.process(TestJavaMail.java:63) </code></pre> <p>I Googled the above error and found <a href="https://issues.jboss.org/browse/AS7-1278" rel="nofollow">there was a bug with my used JBoss version</a>. So, I moved the application to a later <code>JBoss</code> version which was <code>JBoss AS 7.1.1</code> and I succeeded. The servlet successfully sent an email to the destination I had provided for it. </p> <p>I hope this investigation will be helpful to you and to any visitor who is struggling with a similar problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload