Vertx Mail Client config

301 views
Skip to first unread message

Prajeesh K P

unread,
Apr 7, 2021, 12:55:47 AM4/7/21
to ve...@googlegroups.com
Hi All,

I am trying to send E-Mail using vert.x mail client using microsoft exchange. My code is attached below.
public static void main(String[] args) {

Vertx vertx = Vertx.vertx();
MailConfig mailConfig = new MailConfig();
mailConfig.setHostname("smtp.office365.com");
mailConfig.setPort(587);
mailConfig.setLogActivity(true);
mailConfig.setStarttls(StartTLSOptions.REQUIRED);
mailConfig.setLogin(LoginOption.REQUIRED);
mailConfig.setUsername("ma...@company.com");
mailConfig.setPassword("Password");
mailConfig.setSsl(false);

MailClient mailClient = MailClient.create(vertx, mailConfig);
MailMessage message = new MailMessage();
message.setFrom(mailConfig.getUsername());
message.setTo("some...@somecompany.com");
message.setText("This is a Test Mail");

mailClient.sendMail(message,res->{
if(res.succeeded()) {
System.out.println("Mail Sent");
} else {
res.cause().printStackTrace();
}
});
}
when I running this code I am getting this exception

 WARNING: AUTH LOGIN failed 535 5.7.3 Authentication unsuccessful 
io.vertx.core.impl.NoStackTraceThrowable: Failed to authenticate

and when I add the Auth method I it is saying not valid auth method.

Please help with what I should add as Auth method and also let me know if I am doing something wrong.

Regards
Prajeesh K P 

Jonad García San Martín

unread,
Apr 7, 2021, 2:33:52 AM4/7/21
to vert.x
Hello Prajeesh,

You can try with:

mailConfig.setAuthMethods("PLAIN");
PLAIN
LOGIN
MD5
DIGEST-MD5
CRAM-MD5
GSSAPI
OAUTH10A
OAUTHBEARER
XOAUTH2

If none of those works fine, I found instructions to configure your application to connect with exchange via SMTP using the last one (XOAUTH2) here:


You have to register your application and follow a series of steps. I don´t know if vertx mail client support that AUTH METHOD. If don´t you can try to add XOAUTH2 header mannually to the mail, following "AUTHENTICATE XOAUTH2 <base64 string in XOAUTH2 format>" format described in the article.

Greetings.

Prajeesh K P

unread,
Apr 7, 2021, 4:45:49 AM4/7/21
to ve...@googlegroups.com
Thanks Jonad Login auth type worked

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/b8284802-e74a-467d-967a-bdc9db71e376n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages