Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail in javax.mail without authentication

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 to false, but what else should I change?

like image 356
muffin Avatar asked Oct 01 '13 12:10

muffin


People also ask

How can I send email without SMTP server?

The simplest way to send a message is to use QuickSend method of Smtp class (this method is static, it does not require you to create an instance of Smtp class). QuickSend method allows you to send e-mails out even if you do not have an SMTP relay server.

How can I get SMTP server response using JavaMail?

SMTPTransport t = (SMTPTransport)session. getTransport("smtps"); t. send(message); String response = t. getLastServerResponse(); boolean s = t.

What is mail SMTP STARTTLS enable?

smtp. starttls. enable, to "true". When set, if the server supports the STARTTLS command, it will be used after making the connection and before sending any login information.


1 Answers

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.

like image 125
Kris Avatar answered Sep 21 '22 04:09

Kris