Connection refused to host: smtp.gmail.com port: 587 from Spring Boot - spring-boot

I am trying to send email using spring-boot-starter-mail and the result is
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout 5000;
My application.properties are
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=<email>
spring.mail.password=<password>
# Other properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
# TLS , port 587
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.starttls.enable=true
I have tried myriad combinations and all roads lead to this same exception! I can telnet to smtp.gmail.com 587 and receive a response
220 smtp.gmail.com ESMTP e82sm2105370oia.36 - gsmtp
Many links I followed suggested a firewall might be to blame. Has anyone seen this issue?

Are you using a proxy? If your telnet is successful then it’s using some configuration that your spring application lacks, perhaps an environment variable such as HTTP_PROXY is set? The most likely scenario I come across in this situation is this issue. You would them need to set this as normal for any java application by passing the
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128
arguments.

Related

DDEV: How to etablish websocket connections

I'm having some problems to establish a websocket connection to a running ddev container.
Trying wo etablish the connection per JS for example with wss://websocket.ddev.site:3000 ends always up with connection failed.
Websocket PHP library used: Ratchet (http://socketo.me/)
I tried to set the ext. container port in an own docker-compose.yaml or web_extra_exposed_ports in config.yaml but nothig worked so far.
I have managed to run a Websocket connection.
Therefore, I did an entry in config.yaml of DDEV with following Content:
web_extra_exposed_ports:
- name: ratchet
container_port: 3000
http_port: 3000
https_port: 3001
After DDEV restart, it is now possible to establish a Websocket connections with:
HTTP: 'ws://websocket.ddev.site:3000'
HTTPS: 'wss://websocket.ddev.site:3001'
My working example was build with the tutorial on http://socketo.me/docs/hello-world calling above URL with Browser console.

Not able to Configure relay sentry setup with proxy

I want to connect relay to sentry.io via proxy service/application.
Please help me in this I am not able to find any way to put proxy between relay and sentry.
Config.yml
relay:
mode: managed
upstream: “https://sentry.io/”
host: 0.0.0.0
port: 3000
tls_port: ~
tls_identity_path: ~
tls_identity_password: ~
Where I have to set the proxy in relay?
You can replace the upstream location to your proxy service/application and there you need to have another relay which can upload the data to sentry.io
Warn : This will just forward the messages, so configure your first relay in proxy mode.

Connection problem with WinRM and Ansible

I am trying to connect to multiple Windows nodes but I am getting different errors. The behaviour is the same for all of them. I have done it many times successfully in other enviroments, but in this case there must be some problem that I cannot find out. In case it is relevant, my infrastructure consists of a Kubernetes cluster made up of several pods. One of those pods has a container in which I have Ansible installed and it is from which I want to establish the remote connection with machines out of the cluster. Below I show all my attempts to make it work in one of the nodes.
First of all, I have run the script ConfigureAnsibleForRemoting.ps1 to initiate WinRM so that Ansible can connect. The WinRM configuration shows that Basic, Kerberos, Negotiate, and Certificate auth are enabled. Both HTTP and HTTPS listeners are configured too:
WinRM configuration and listeners
To check that everything is set up correctly, I have carried out some tests:
Run Test-WSMan
Log in powershell session from remote machine
Node is reachable from the container
Tests
I have used Basic, NTLM and Certificate auth. Here is my inventory (I do not utilize a domain user but a local user) and the result when I make a win_ping with Ansible in each case:
- Basic: port 5986
[prueba_cinco]
host ansible_host=IP
[prueba_cinco:vars]
ansible_user=user
ansible_password=pass
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
Basic: port 5986 output
- Basic: port 5985
[prueba_cinco]
host ansible_host=IP
[prueba_cinco:vars]
ansible_user=user
ansible_password=pass
ansible_connection=winrm
ansible_port=5985
Basic: port 5985 output
This is the expected behaviour, since AllowUnencrypted in the winrm configuration is set to false.
Just to gain more insight into the problem, I allowed unencrypted traffic, and after that the connection could be established normally:
WinRM config: AllowUnencrypted and Basic: port 5985 output 2
- NTLM: port 5986
[prueba_siete]
host ansible_host=IP
[prueba_siete:vars]
ansible_user=user
ansible_password=pass
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=ntlm
NTML: port 5986 output
- NTLM: port 5985
[prueba_siete]
host ansible_host=IP
[prueba_siete:vars]
ansible_user=user
ansible_password=pass
ansible_connection=winrm
ansible_winrm_transport=ntlm
ansible_port=5985
NTLM: port 5985 output
This works, although a huge error is obtained. I later tried this option with a domain user and the credentials were rejected.
- Certificate: port 5986 (only works with HTTPS)
For this method, I have followed the procedure of the official documentation. I have generated a certificate with New-SerfSignedcertificate in Powershell. Then I have converted the PFX file created to a private key with OpenSSL (that also contains the public key). By last, I have imported a certificate to the Certificate Store and mapped the certificate to an account.
[WINDOWS]
host ansible_host=IP
[WINDOWS:vars]
ansible_connection='winrm'
ansible_winrm_cert_pem='cert_win.pem'
ansible_winrm_cert_key_pem='cert_win.pem'
ansible_winrm_transport='certificate'
ansible_winrm_scheme='https'
ansible_winrm_server_cert_validation='ignore'
Certificate: port 5986 output
As you may have noticed, when I try to connect through the port 5986, I always obtain a time out (Read timed out) regardless of the method or credentials. I have increased the execution time out, but the result is the same. On the other hand, the port 5985 seems to work but an error related to headers appears and I do not know the reason. Anyway, I only would use this one as a last option, since I need to use the port 5986.
To make sure that the container configuration is not what is causing these issues, I have deployed the same image in another environment and everything works perfectly when I try to connect to Windows nodes, I can connect without any error.
Does anyone know what is happening?
Thank you in advance.

SpringBoot Aruba Mail

I want to send a mail with Aruba host and SpringBoot 2.1.3 application. Before start I have done a little test, believing I would have found no problem.. I was wrong.
This is my application.properties
spring.mail.host=smtps.aruba.it
spring.mail.port=465
spring.mail.username=***
spring.mail.password=***
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.debug=true
Don't works, the debug says me that it cant connect to the hosts.. and, while it trying to do it, the debugger write:
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtps.aruba.it", port 465, isSSL false
What's wrong?? I trying to send mail with gmail and hotmail with the same parameters and all works well.. damned Aruba..
Thank you
Solution:
spring.mail.host=smtps.aruba.it
spring.mail.port=465
spring.mail.username=***
spring.mail.password=***
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
Hope helps..
I'm not 100% sure about it but try to use as host smtp without "s" cause you are not using a secure SSL connection:
smtp.aruba.it
More informations : https://serversmtp.com/smtp-aruba/
If you want to use STARTTLS switch to port 587, port 465 is for implicit SSL not for explicit
spring.mail.host=smtps.aruba.it
spring.mail.port=587
spring.mail.username=***
spring.mail.password=***
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true

Mail properties in Production - Jhipster 4.2.8

I have the following configuration of the mail account of my company in develop, which goes perfectly:
mail:
host: smtp.xxx.es
port: 587
username: notifications-noreply#xxx.es
password: xxxx
protocol: smtp
#tls: true
properties.mail.smtp:
auth: true
from: notifications-noreply#xxx.es
starttls.enable: true
ssl.trust: smtp.xxx.es
I copy de same data from "application-dev.yml" to "application-prod.yml".
I make the deployment in Google Cloud.
It does not send me mails and the logs tells me the following:
: Email could not be sent to user 'joseluis.xxx#xxx.com': Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.xxx.es, 587; timeout -1;
nested exception is:
java.net.ConnectException: Operation timed out (Connection timed out). Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.xxx.es, 587; timeout -1;
nested exception is:
java.net.ConnectException: Operation timed out (Connection timed out)
Can somebody help me?
As described in the Google Cloud documentation you can't send e-mail from your Google Cloud VM using port 587. So this has nothing to do with JHipster, it's a limitation from your cloud provider.
I personally use Mailgun, which uses port 2525 (which is allowed by Google Cloud), here is my configuration for https://start.jhipster.tech (a JHipster application that runs on Google Cloud):
spring:
mail:
host: smtp.mailgun.org
port: 2525
username: xxxxx#mg.jhipster.tech
password: xxxxx
As Mailgun provides a generious free tier you can test this for free - in fact I use it in production and haven't paid anything yet!

Resources