I am using the JavaMail to connect and verify the username and password in office 365.
I use the following java code to check the connectivity,
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.auth", true);
System.out.println("Before Session... #################################################");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username_xxxx#xxx.com", "password_xxxxx");
}
});
System.out.println("After Session... #################################################");
session.setDebug(true);
Transport transport = session.getTransport("smtp");
System.out.println("Before Connection... #################################################");
transport.connect();
System.out.println("After Connection... #################################################.");
if(transport.isConnected()) {
System.out.println("Connected Successfully : " + transport);
System.out.println("#################################################");
} else {
System.out.println("Not Connected : " + transport);
}
transport.close();
Mostly 70% of the time, transport.connect() works as expected where the greeting message (220) is received in less than 100ms but there are sometimes (say after 3 hours of the application is deployed in webserver), transport.connect() takes more than 2 minutes to send the greetings message
2020-08-23 11:38:16,930 ERROR [stderr] (default task-415) Before transport connection ::: Sun Aug 23 11:38:16 UTC 2020
2020-08-23 11:38:16,931 INFO [stdout] (default task-415) DEBUG SMTP: useEhlo true, useAuth true
2020-08-23 11:38:16,933 INFO [stdout] (default task-415) DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
2020-08-23 11:40:27,657 INFO [stdout] (default task-415) 220 BL0PR02CA0082.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 23 Aug 2020 11:40:27 +0000
I enabled the session logs and we could see the 11:40:27,657 log (220 BL0PR02CA0082.outlook.office365.com Microsoft ESMTP MAIL Service ready) takes a long time to receive.
I did some surfing and found the root cause is due to the SMTP server https://www.rfc-editor.org/rfc/rfc5321#section-4.5.3.2.1 where the greetings message 220 can be send in delay!
How can we avoid this delay is my question ?
Anyhelp is appreciated!
Thanks,
Harry
Related
SubEthaSMTP server running fine on port 25001. After a successful authentication from my client code to Subethasmtp server i am having this error message org.subethamail.smtp.server.Session: Unexpected error in the SMTP handler thread
java.lang.NoClassDefFoundError: jakarta/mail/internet/AddressException
This is my SMTPServerConfig class
#Configuration
public class SMTPServerConfig {
private final SMTPServer smtpServer;
private final SimpleMessageListener marketingMsgListener;
private final UsernamePasswordValidator authValidator;
private final EasyAuthenticationHandlerFactory easyAuth;
public SMTPServerConfig(SimpleMessageListener marketingMsgListener) {
authValidator = new SimpleAuthValidatorImpl();
easyAuth = new EasyAuthenticationHandlerFactory(authValidator);
this.marketingMsgListener = marketingMsgListener;
this.smtpServer = SMTPServer
.port(25001)
.simpleMessageListener(this.marketingMsgListener)
.requireAuth(true)
.authenticationHandlerFactory(easyAuth)
.hostName("localhost")
.hideTLS(false)
.enableTLS(true)
.requireTLS(false)
.requireAuth(true)
.connectionTimeout(1, TimeUnit.MINUTES)
.maxMessageSize(10000)
.maxConnections(20)
.build();
this.smtpServer.stop();
this.smtpServer.start();
}
I am using usernamepasswordvalidator
#Configuration
public class SimpleAuthValidatorImpl implements UsernamePasswordValidator {
private final String CREDENTIALS_LOGIN = "christclau";
private final String CREDENTIALS_PASSWORD = "password";
#Override
public void login(String username, String password, MessageContext context) throws LoginFailedException {
if(CREDENTIALS_LOGIN.equals(username) && CREDENTIALS_PASSWORD.equals(password)){
System.out.println("yes Authenticated successfully");
}else{
System.err.println("no Invalid authentication !");
throw new LoginFailedException();
}
}
}
This is my mail client to send message to the server
public void sendMail(Mail mail) {
final String username = "christclau";
final String password = "password";
Properties prop = new Properties();
prop.put("mail.smtp.host", "localhost");
prop.put("mail.smtp.port", "25001");
prop.put("mail.smtp.auth", "true");
//prop.put("mail.debug", "true");
//prop.put("mail.smtp.starttls.enable", "true"); //TLS
Session session = Session.getInstance(prop,
new javax.mail.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
session.setDebug(true);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(mail.getFrom()));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse(mail.getTo())
);
message.setSubject(mail.getSubject());
message.setText("HI you have done sending mail with outlook");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
e.printStackTrace();
}
}
This is the output message
DEBUG: setDebug: Jakarta Mail version 1.6.7
DEBUG: getProvider() returningjavax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=localhost, user=MY PC, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "localhost", port 25001, isSSL false 220 localhost ESMTP SubEthaSMTP null
DEBUG SMTP: connected to host "localhost", port: 25001
EHLO DESKTOP-FFJA5IP
250-localhost
250-8BITMIME
250-SIZE 10000
250-STARTTLS
250-CHUNKING
250-AUTH PLAIN LOGIN
250 Ok
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10000"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "Ok", arg ""
DEBUG SMTP: protocolConnect login, host=localhost, user=christclau, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
yes Authenticated successfully
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<christoozu#gmail.com>
2022-02-26 11:21:40.081 ERROR 9452 --- [127.0.0.1:50466] org.subethamail.smtp.server.Session : Unexpected error in the SMTP handler thread
java.lang.NoClassDefFoundError: jakarta/mail/internet/AddressException
at org.subethamail.smtp.internal.command.MailCommand.execute(MailCommand.java:74) ~[subethasmtp-6.0.1.jar:na]
at org.subethamail.smtp.internal.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:32) ~[subethasmtp-6.0.1.jar:na]
at org.subethamail.smtp.internal.server.RequireAuthCommandWrapper.execute(RequireAuthCommandWrapper.java:35) ~[subethasmtp-6.0.1.jar:na]
at org.subethamail.smtp.internal.server.CommandHandler.handleCommand(CommandHandler.java:86) ~[subethasmtp-6.0.1.jar:na]
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:261) ~[subethasmtp-6.0.1.jar:na]
at org.subethamail.smtp.server.Session.run(Session.java:170) ~[subethasmtp-6.0.1.jar:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.ClassNotFoundException: jakarta.mail.internet.AddressException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
... 9 common frames omitted
This is my dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>subethasmtp</artifactId>
<version>6.0.1</version>
</dependency>
Spring Boot 2.6 and earlier still use the javax.mail namespace for JakartaMail (formerly JavaMail), while your SubEtha SMTP version seems to expect the jakarta.mail namespace. Spring Boot explicitly specifies versions of the JakartaMail package, see Spring Boot Dependency Versions and search for jakarta.mail. For Spring Boot 2.6.4, it lists version 1.6.7, and that version is still based on the javax.mail namespace.
You need to downgrade SubEtha SMTP to a version that still uses the javax.mail namespace of JakartaMail/JavaMail, and wait for Spring Boot 3 before using a version that needs the jakarta.mail namespace.
In theory, you can also set the Maven property jakarta-mail.version to 2.0.1, but this could cause problems in other parts of Spring Boot, so I do not recommend that.
I'm facing an error using javaMail & IMAPS to read emails on email account of my company hosted in office 365.
I'm using this test class:
public class TestMail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties props = System.getProperties();
props.put("mail.imaps.auth.plain.disable","true");
props.setProperty("mail.imaps.timeout", "100000");
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.ssl.enable", "true");
try {
Session session = Session.getInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "my-name#mycompagny.com", "MY_PASSWORD");
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message messages[] = inbox.getMessages();
for(Message message:messages) {
System.out.println(message);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
}
}
I'm getting the following error:
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: disable AUTH=PLAIN
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [UABSADIAUAAyADYANABDAEEAMAAwADAANAAuAEYAUgBBAFAAMgA2ADQALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, user=my-name#mycompagny.com, password=<non-null>
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO LOGIN failed.
javax.mail.AuthenticationFailedException: LOGIN failed.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
at javax.mail.Service.connect(Service.java:295)
at com.afklm.bagdss.task.TestMail.main(TestMail.java:25)
I have problem with randomly login failed. By one hour is happening 2-4 times, and similar time, for example: about 14:26, 14:48, 15:26, 15:49, etc.
I use JavaMail(ver. 1.5.6) to email processing. Mailbox is Microsoft Exchange.
Application run every 5 minute to connect to mailbox.
Pseudocode for email processing:
estabilishConncetion()
prepareMailbox()
downloadEmails()
moveEmailsToSOmething()
closeConnection()
Code connection is like this:
public void establishConnection() throws ConnectionException {
logger.info("Establish connection... ");
props = new Properties();
props.setProperty("mail.imaps.ssl.enable", "true");
props.setProperty("mail.imaps.port", 993);
props.setProperty("mail.imaps.timeout", 60000);
props.setProperty("mail.imaps.connectiontimeout",60000 );
props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.imaps.auth.ntlm.disable", "true");
props.put("mail.imaps.auth.gssapi.disable", "true");
props.setProperty("mail.debug", "true"); // only for test
Session session = Session.getInstance(props, new Authenticator(){
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(somename, somepassword);
}
});
try {
store = session.getStore("imaps");
store.connect(EmailServerAddress, EmailAddress,Password);
} catch (MessagingException e) {
throw new ConnectionException(" Problem occured when try connect to host: " + ServerAddress + " on address: " +EmailAddress);
}
logger.info("Connected to mailbox.");
}
Logging when connected:
DEBUG IMAPS: trying to connect to host "somehost", port 993, isSSL true]]
* OK The Microsoft Exchange IMAP4 service is ready.]]
A0 CAPABILITY]]
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN
STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A0 OK CAPABILITY completed.]]
DEBUG IMAPS: protocolConnect login, host=somehost,
user=someuser, password=]]
DEBUG IMAPS: mechanism LOGIN not supported by server]] DEBUG IMAPS:
LOGIN command trace suppressed]] DEBUG IMAPS: LOGIN command result: A1
OK LOGIN completed.]]
A2 CAPABILITY]] * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI
AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A2 OK CAPABILITY completed.]]
DEBUG IMAPS: AUTH: NTLM]] Connected to mailbox.]]
Logging when not connected:
DEBUG IMAPS: trying to connect to host "somehost", port 993, isSSL
true]]
* OK The Microsoft Exchange IMAP4 service is ready.]]
A0 CAPABILITY]]
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN
STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A0 OK CAPABILITY completed.]]
DEBUG IMAPS: protocolConnect login, host=somehost, user=someuser,
password=]]
DEBUG IMAPS: mechanism LOGIN not supported by server]] DEBUG
IMAPS: LOGIN command trace suppressed]] DEBUG IMAPS: LOGIN command
result: A1 NO LOGIN failed.]] //trying to login one more time with
failure
I checked this and its ok in my code:
1. Using JavaMail to connect to IMAP getting "A1 NO LOGIN failed" exception
2. https://javaee.github.io/javamail/FAQ#Exchange-login
3. I have unit test realted with connection and they always passed
Any sollution, clues, how to better debug this? :)
I've seen several posts that offer a solution to something very similar to my situation but for whatever reason it does not work for me.
For example, here it's presented as a working sample illustrating OP's related problem and here as an actual answer.
I need to send e-mail as myself from my Exchange account via SMTP using SSO UserID and Password. This all happens in a restricted corporate environment.
From what I understand from the debug info I'm successfully connecting to an SMTP server and then fail user authentication with 530 5.7.1 Client was not authenticated. NTLM authentication itself seems to be enabled.
DEBUG:
DEBUG: setDebug: JavaMail version 1.5.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "server.bank.com", port 25, isSSL false
220 server1.corp.bank.com Microsoft ESMTP MAIL Service ready at Mon, 24 Aug 2015 17:15:24 -0400
DEBUG SMTP: connected to host "server.bank.com", port: 25
EHLO server2.corp.bank.com
250-server1.corp.bank.com Hello [xxx.xxx.xxx.xxx]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-X-ANONYMOUSTLS
250-AUTH NTLM LOGIN
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250-XRDST
250 XSHADOW
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Found extension "XSHADOW", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<first.last#bank.com>
530 5.7.1 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated
Essential part of my code:
static void sendEmail(){
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", "25");
// props.setProperty("mail.debug", "true");
// props.setProperty("mail.debug.auth", "true");
props.setProperty("mail.smtp.starttls.enable","true");
props.setProperty("mail.smtp.auth.mechanisms", "NTLM");
props.setProperty("mail.smtp.auth.ntlm.domain", user_sso_domain);
// Session session = Session.getDefaultInstance(props);
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user_sso_id, user_sso_password);
}
});
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(email_from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email_to));
message.setSubject("Test Message");
message.setText("This is my test message");
Transport.send(message);
} catch (Exception ex) {
ex.printStackTrace();
}
}
I would appreciate your suggestions for further troubleshooting.
EDIT
Working code after implementing the fix and better practices from the accepted answer:
private static void sendEmail(){
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", "25");
// props.setProperty("mail.debug", "true");
// props.setProperty("mail.debug.auth", "true");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.starttls.enable","true");
props.setProperty("mail.smtp.auth.mechanisms", "NTLM");
props.setProperty("mail.smtp.auth.ntlm.domain", user_sso_domain);
Session session = Session.getInstance(props);
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(email_from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email_to));
message.setSubject("Test Message");
message.setText("This is my test message");
Transport.send(message, user_sso_id, user_sso_password);
} catch (Exception ex) {
ex.printStackTrace();
}
}
You need to set "mail.smtp.auth" to "true".
Or, better yet, fix these common mistakes and make your program much simpler.
Trying to send an email using java mail api. And I keep getting MailConnectException. I have tried multiple ways to solve it without success.
Exception is thrown by this statement
transport.connect("smtp.gmail.com", "someone#gmail.com", "myPassword");
Can anyone tell me what I'm doing wrong?
public static void main(String[] args) {
String host = "smtp.gmail.com";
String from = "someone#gmail.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", "myPassword");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.auth", "true");
try{
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, "someone#hotmail.com");
message.setSubject("sending in a group");
message.setText("Welcome to JavaMail");
Transport transport = session.getTransport("smtp");
transport.connect("smtp.gmail.com", "someone#gmail.com", "myPassword");//CAUSES EXCEPTION
transport.sendMessage(message, message.getAllRecipients());
}catch(MessagingException e){
e.printStackTrace();
}
}
Stack trace:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at com.karmacrafts.util.CustomEmail.main(CustomEmail.java:127)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:301)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
... 4 more
This looks like network problem. Even though it could occur due to variety of reasons, like :-
"Couldn't connect to host, port" could be caused by wrong host name, wrong port, a blocking firewall (on the server, on gateways, even on your own machine), network failure, server downtime, etc.
Can you connect to the mail server using telnet ?
Also see this FAQ for some mistakes you committed http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes
Read this answer on how to send emails using gmail https://stackoverflow.com/a/47452/3107043
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
props.put("mail.smtp.port", "587"); transport.send(message);
After 8 hours of pain, I've solved this by turning off:
1) my windows firewall
2) my antivirus software
hope this helps
I met the same problem, and the reason is that I opened a vpn. Hope this will be helpful.
For me, de-activating firewall and anti-virus did not work.
I tried the alternate ports given in the mailtrap's SMTP settings
25 or 465 or 587 or 2525
changing spring.mail.port to 2525 in the applications.properties file worked for me
Open /etc/postfix/main.cf
Search /inet_interfaces line and comment localhost, un-comment all:
Restart the SMTP server using terminal command "postfix restart"