Mail sending -SMTP error with javaMailSender - java

I am running a program to send email using spring boot with gmail smtp.
The same code works fine in my personal laptop.
But when I try to run it in office laptop it doesn't work and says
SMTP timeout:
Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;
I feel it is because of firewall or proxy.
I tried to check from Outlook but could not get smtp name , i tried some hit and trial also.
Any possible solution.

Related

unable to send email on docker container from port 465

I tried to send an email from port 465, it works well on IDEA. But when I deployed it on docker, the email send failed. The error message is:
javax.mail.MessagingException: Could not connect to SMTP host: smtpdm.aliyun.com, port: 465, response: -1
Then I tried to change the port to 25, the email sent success.
Change the smtp server seems nothing better.
How can I send mail from port 465 on docker container?
make sure that the port is available on the host machine and ports are mapped correctly when you start the docker image. also, make sure that postfix is installed in your docker image and is active (sudo postfix status or sudo systemctl status postfix).
if both of theses conditions are met but it still don't work please also Try to set these values to:
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
in /etc/postfix/main.cf in the docker container.

Spring Boot - Java Mail - Couldn't connect to host

I've implemented the email manager using JavaMailSender into my Java application, configured with Gmail email, and locally tested.
I'm using a free domain by freenom.
in localhost on my pc everything working perfectly. But deploying on the server the application obtains this error:
c.m.a.m.components.EmailManager : sendRegisterEmail Exception: Mail server connection failed;
nested exception is com.sun.mail.util.MailConnectException:
Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;
nested exception is:
java.net.UnknownHostException: smtp.gmail.com. Failed messages:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;
nested exception is:
java.net.UnknownHostException: smtp.gmail.com
test done
Generating an application password
Using directly the host IP
Using port 465 and 25
Disabling VPS firewall
Used another mail provider
application.properties
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=***********#gmail.com
spring.mail.password=***********
spring.mail.properties.mail.debug=false
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.mime.charset=UTF-8
spring.mail.transport.protocol=smtp
Try to change spring.mail.port to 465. This might help.
Port 587 is technically correct. However, many ESPs have adopted implicit TLS on port 465.
Also, there's probably a firewall preventing you from connecting directly, you may need to connect through a proxy.

Simple Java Mail SMTP host

I am using Simple Java Mail API in order to send emails from my Spring Boot application. The app's owner was my colleague who doesn't work with me now. In my application.properties file I have the following config
simplejavamail:
smtp:
host: 172.28.94.229
port: 25
javaxmail:
The question is that I can't understand what host is this? Which server my emails go to? Is this something provided by Simple Java Mail, but I couldn't find anything in their documentation.
This IP address is not publicly routable on the Internet but is reserved and used for private or local networks.
For you information the following IPv4 address spaces are not Internet routable:
10.0.0.0/8 IP addresses: 10.0.0.0 – 10.255.255.255
172.16.0.0/12 IP addresses: 172.16.0.0 – 172.31.255.255
192.168.0.0/16 IP addresses: 192.168.0.0 – 192.168.255.255
You can try the following command
telnet 172.28.94.229 25
and see if you get a timeout (meaning that no service is listening on that IP/Port) or you are connected to some service.
If this IP/Port exists and you get a connection opened, then you should ask your company's system admin for more information on that SMTP server.
If you cannot get connected, maybe this is just a mock / not real SMTP server.

Cannot send mails via outlook through java application

Have the following mail configuration settings :
mail.smtp.host=smtp.us.deloitte.com
mail.smtp.socketFactory.port=25
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.auth=true
mail.smtp.port=25
and the following properties :
mail.password=password
mail.from=sam#xyz.com
mail.to=sam#xyz.com
mail.subject=Status of Data pushed
I get the following error :
java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.us.deloitte.com, port: 25;
nested exception is:
java.net.SocketException: Permission denied:
The same code when I use gmail as the 'from' account and the Outlook account in 'to', it works.
I tried setting setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true, also disabled iPv6 on Windows 7 box, but nothing seems to work
Just an observation: You are using STMPS protocol, and most SMTPS servers still communicates on the deprecated port 465 or the standardized port 587 and not 25.

Could not connect to SMTP host error in my local only

I am getting this error while trying to send mail through java mail. It used to work for me, but recently I switched to jdk7 and glassfish 3.1.2. I tried to switch it back to jdk6 also but it's not working anymore, here is the error I'm getting:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.illumina.com, port: 25;
nested exception is:
java.net.SocketException: Permission denied: connect
Telnet and ping to this server is fine. Its working from other systems. Only my local setup is throwing this error.
Any ideas?

Categories

Resources