I'm trying to send java email without senders password. Below you can see the code. I change mail.smtp.auth from true to false. There is a override method which method name getPasswordAuthentication():
public class SendMailUtilNineThirty implements Runnable {
final private String SMTP_SERVER = "192.186.16.14";
final private String SMTP_PORT = "135";
final private String TO_EMAIL = "saman@thal.com";
final private String TO_EMAIL = "dumidu@thal.com";
final private String FROM_EMAIL = "samanchandana@thal.com";
final private String FROM_EMAIL_PASSWORD = "1qaz2wsx@";
public void sendEmail(String emailContent, String subject) {
try {
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_SERVER);
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.auth", "false");
Session mailSession = Session.getInstance(props, new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(FROM_EMAIL, FROM_EMAIL_PASSWORD);
}
});
mailSession.setDebug(true);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(FROM_EMAIL));
message.addHeader("site", "thal.com");
message.addHeader("service", "Thal Service");
message.setSentDate(new Date());
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(TO_EMAIL));
message.setSubject(subject);
How to send email without password authentication? Thanks.