Send mail in javax.mail without authentication
67,440
private void createSession() {
properties.put("mail.smtp.auth", "false");
//Put below to false, if no https is needed
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", server);
properties.put("mail.smtp.port", port);
session = Session.getInstance(properties);
}
I think, this would suffice.
Author by
muffin
Updated on February 14, 2020Comments
-
muffin over 4 years
I am using javax.mail to send mails in Java. Now that a part of the concept of my project changed I have to send a mail without authentication. I will have to change my createSession() method:
private void createSession() { properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.host", server); properties.put("mail.smtp.port", port); session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); }
It is rather obvious that I should change
mail.smtp.auth
tofalse
, but what else should I change? -
Bill Shannon over 10 yearsAnd of course it depends on your server being configured to allow you to send mail without authenticating first. That might work fine within an intranet, otherwise it's an invitation to spam.
-
Sami almost 8 yearsStill says
Authentication Required. Please contact support
-
Kris almost 8 yearsAuthentication is a server policy. If the server requires authentication - you have to provide it!!
-
Farooque over 6 yearsput properties.put("mail.smtp.starttls.enable", "false"); as well.It worked for this after this change.
-
R.A over 4 yearsPelase explain your answer.
-
Vishwa Pratap about 4 yearsThis does not work if change mobile date, can anyone help me in this.