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!
Related
I config spring email by add 2 step verification and password is Generated App Password
Help me know why I wrong :(
I want to send mail as a reminder in Admin Server
But get this error:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout 20000
...
I have searched a lot online but still don't work
My Admin Server Application YAML configuration file:
spring:
security:
user:
name: admin
password: 123456
boot:
admin:
notify:
mail:
enabled: true
# receivers
to: xxx#outlook.com
ignore-changes: {"UNKNOWN:UP"}
# copy-to list
cc:
from: Spring Boot Admin<xxx#gmail.com>
# mail sender
mail:
host: smtp.gmail.com
port: 587
username: xxx#gmail.com
# with 2-factor authentication, we should get app password from Google
password: my-app-password
default-encoding: UTF-8
properties:
mail:
smtp:
connectiontimeout: 20000
timeout: 20000
writetimeout: 20000
starttls:
enable: true
required: true
auth: true
ssl:
enable: true
required: true
debug: true
server:
port: 8081
I config the settings with the help of this instruction
btw, 2-factor authentication is enabled with my Google account, so I followed this instruction to get my "app password"
But after I start my Admin Server application, and wait 20 second, the error appears
I have tried change port to 465, not working
I have tried spring.mail.properties.mail.smtp.socketFactory.port and configure it to 465, not working
I'm using Windows 11 and windows firewall has no Outbound rule against java, java platform, intelliJ idea, there're Inbound rules that block java and java(TM) platform, not working
With my config above, Admin Server should send a mail to xxx#outlook.com from xxx#gmail.com.
I have configured zuul proxy and eureka naming server for my spring boot application. Zuul proxy run on port 8765 and eureka runs on port 8761.
Also two other microservices, user-service and message-service run on port 8081 and 8082.
Also I have used swagger for the zuul proxy service where i can find all microservices api in one place.
Swagger configuration in Zuul proxy service
#Component
#Primary
#EnableAutoConfiguration
public class Controller implements SwaggerResourcesProvider{
#Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources= new ArrayList<>();
SwaggerResource user = new SwaggerResource();
user.setName("USER-SERVICE");
user.setLocation("/api/user/v2/api-docs");
user.setSwaggerVersion("2.0");
resources.add(user);
SwaggerResource message = new SwaggerResource();
message.setName("MESSAGE-SERVICE");
message.setLocation("/api/message/v2/api-docs");
message.setSwaggerVersion("2.0");
resources.add(message);
return resources;
}
}
application.yml of Zuul proxy
server:
port: 8765
eureka:
client:
serviceUrl:
defaultZone: http://eureka-naming-server:8761/eureka/
instance:
prefer-ip-address: true
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
zuul:
prefix: /api
sensitive-headers: Cookie,Set-Cookie
routes:
user-service:
path: /user/**
service-id: USER-SERVICE
message-service:
path: /message/**
service-id: MESSAGE-SERVICE
Also i have used docker-compose file to up the docker microservices with default subnet (169.254.3.0/24).
ip address of user-service is 169.254.3.6
ip address of message-service is 169.254.3.10
Here is the issue
When I call these services via zuul proxy swgger ui, often i am getting 500 error. That for the first time i hit the specific url it throws 500 error.
but after few attempt i get the response.
Zuul log which indicate problem
com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out
I have no idea about 172.22.97.14:8081, why is not try to connect 172.22.97.14:8081 instead of connect to 169.254.3.6:8081
Can someone help me to understand what is happening in here..
Any help would be grateful !
[Edit]
zuul proxy container ip is 169.254.3.10
This problem occured on my project when I was using the same Zuulserver for developing microservices on localhost and DEV environment (when I started microservis on localhost it connected to zullserver on DEV env.). Then when I tried to call some operation through zuulserver it tried to connect to microservis not on DEV env. but on my machine.
I suspect the same problem on your side and IP on which you are developing your application is 172.22.97.14:8081.
I have written an email service using Spring Email and then used Greenmail to test the email service. But while running the test case it gives an error Authentication failed as below:
javax.mail.AuthenticationFailedException: 535 5.7.0 Authentication credentials invalid at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
How can this error be resolved without giving my username/password in the code. Note that I have also tried giving username/password but it failed with the same exception. Thanks for any help.
greenMail = new GreenMail(new ServerSetup(2525, "127.0.0.1", "smtp"));
greenMail.setUser("username", "secret");
When Setting up your greenmail instance for testing you need to use the setUser and enter
username and password above and then add the properties specified in the #One Guy post above this. has worked for me after I received the Authentication credentials invalid Exception.
Hope this helps anyone facing a the issue
See AuthenticationDisabledTest.java how to configure a GreenMail junit test using disabled authentication.
Looks like you don't added the mock credentials i.e. a a resource file called application-test.yml file which is located in the src/test/resources folder.
application.yml
spring:
mail:
default-encoding: UTF-8
host: localhost
jndi-name:
username: username
password: secret
port: 2525
properties:
mail:
debug: false
smtp:
debug: false
auth: true
starttls: true
protocol: smtp
test-connection: false
You can take a look an example by following link:
https://memorynotfound.com/spring-mail-integration-testing-junit-greenmail-example/
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.