spring - Possible causes of org.springframework.mail.MailSendException / java.net.ConnectException? -
i have spring boot application once day should send emails users needs informed specific events day. i'm using spring-boot-starter-mail
dependency , javamailsender
provided it.
my application.proiperties config mails looks (with proper host, user , password data ofcourse):
spring.mail.host = myhost.com spring.mail.username = user@myhost.com spring.mail.password = mypassword spring.mail.port = 25 spring.mail.properties.mail.smtp.auth = true
and code responsible sending mails is:
private void sendmessage(string email, string text, string subject) { try { mimemessage message = javamailsender.createmimemessage(); mimemessagehelper helper = new mimemessagehelper(message, true); helper.setfrom(sender); helper.setsubject(subject); helper.setto(email); helper.settext(text, true); javamailsender.send(message); } catch (messagingexception e) { e.printstacktrace(); } catch (mailexception e) { e.printstacktrace(); } }
where javamailsender
autowired , sender set value of spring.mail.username
property. method called in loop within scheduled job, 10 20 times (for each email should notified).
it works no problem when run on local machine or company server, when application running on pivotal cloud foundry, sends 2 or 3 first emails , throws
org.springframework.mail.mailsendexception: mail server connection failed; nested exception com.sun.mail.util.mailconnectexception: couldn't connect host, port: myhost.com, 25; timeout -1; java.net.connectexception: connection timed out. failed messages: com.sun.mail.util.mailconnectexception: couldn't connect host, port: myhost.com, 25; timeout -1; ...
what can possible cause of this? tried find answer every described problem find mails not working @ all, due bad configuration , not case (i think) can successfuly send emails 2 different machines (both of them outside of mailing host local network) can't pivotal cloud (or more specific - can partially before exception arise).
Comments
Post a Comment