0

I am using java, and wilfly 17 running on ubuntu 18 and would like to send an e-mail via localhost / a remote host, i.e. gmail, using this server. I have implemented the solution described in

send mail via localhost

and then tried implementing the solution described in

send mail via remote host

But, unfortunately, in both cases I am getting one and the same exception

    Couldn't connect to host, port: localhost, 25; timeout -1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused (Connection refused)
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)

respectively:

    Couldn't connect to host, port: mail.google.com, 25; timeout -1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.google.com, 25; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection timed out (Connection timed out)
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
    at javax.mail.api@1.6.2//javax.mail.Service.connect(Service.java:388)       

Regarding allowing outbound connections on my Ubuntu system, I have allowed all outbound connections as described in

allow inbound/ outbound connections Ubuntu

I just have tried sending an email through WildFly 17 running on Windows 10, but I am getting the same exception as above:

    (default task-6) Couldn't connect to host, port: mail.google.com, 25; timeout -1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.google.com, 25; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection timed out: connect
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)
    at javax.mail.api@1.6.2//com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
    at javax.mail.api@1.6.2//javax.mail.Service.connect(Service.java:388)
Alex Mi
  • 1,409
  • 2
  • 21
  • 35
  • Google doesn't allow unencrypted smtp traffic, and you aren't running a smtp server on your ubuntu. `sudo apt install mailutils` – Elliott Frisch Jan 10 '20 at 05:03
  • @ElliottFrisch it seems you haven't read my whole question. Part (1) does not concern google at all, but it is still not working; And, it since I am using WildFly, I do have a smtp server, don't I ? – Alex Mi Jan 11 '20 at 03:43
  • 1) "mail.google.com" **is** google. 2) No. SMTP == Simple Mail Transport Protocol. Wildfly is **not** a SMTP server. – Elliott Frisch Jan 11 '20 at 03:47

1 Answers1

0

Thank you guys for your comments!

Ultimately I solved the problem by following exactly the steps listed here:

Configure WildFly to send eMails

then, after having recieved the exception

    javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8

I logged on into my gmail account, on behalf of which I wanted to send e-mails, and enabled the option in this link:

Enable less secure apps gmail

Then I tested my solution on both Ubuntu 18.04 and Windows 10 and it worked in both cases!

Alex Mi
  • 1,409
  • 2
  • 21
  • 35