I’m trying to setup some simple mail service on Wildfly 8.1
with Gmail(for testing).
For some reason, every time I transport the Mail, Wildfly tries to connect to localhost
instead of the assigned outbound-socket
!
Error:
13:22:34,164 ERROR [stderr] (default task-22) com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
13:22:34,164 ERROR [stderr] (default task-22) nested exception is:
13:22:34,165 ERROR [stderr] (default task-22) java.net.ConnectException: Connection refused: connect
13:22:34,165 ERROR [stderr] (default task-22) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
standalone.xml
...
<mail-session name="java:jboss/mail/gmail" debug="true" jndi-name="java:jboss/mail/gmail">
<smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true" username="user@gmail.com" password="pass"/>
</mail-session>
...
<outbound-socket-binding name="mail-smtp">
<remote-destination host="smtp.gmail.com" port="465"/>
</outbound-socket-binding>
Then I just try and send a mail:
@Stateless
public class SendMail {
@Resource(mappedName = "java:jboss/mail/gmail")
private Session mailSession;
public String send() {
MimeMessage m = new MimeMessage(mailSession);
try {
m.setRecipients(Message.RecipientType.TO, "test@mail.com");
m.setContent("Test from Wildfly","text/plain");
Transport.send(m);//throws exception
} catch (MessagingException e) {
e.printStackTrace();
}
...
I've tried "name
" & "lookup
" in the @Resource
annotation but it just keeps wanting to connect to localhost
, for which there isn't even an outbound-socket
.
What am I missing?