javax.mail.AuthenticationFailedException: 535 No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
I am trying to send mail using below program :-
public class mail {
public static void main(String[] args) {
final String username = "****@gmail.com";
final String password = "****";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("piyush.mundada89@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("piyush.mundada89@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n Hi" );
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
But when I run this , I am getting below error
javax.mail.AuthenticationFailedException: 535 No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at mail.mail.main(mail_with_Attachment.java:68)
Please help me..........!
public class mail {
public static void main(String[] args) {
final String username = "****@gmail.com";
final String password = "****";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("piyush.mundada89@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("piyush.mundada89@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n Hi" );
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
But when I run this , I am getting below error
javax.mail.AuthenticationFailedException: 535 No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at mail.mail.main(mail_with_Attachment.java:68)
Please help me..........!
have you added required jars for programme in java build path.
ReplyDeleteThanks for your reply.
DeleteBut, I have 'javaee.jar' and 'mail.jar' in java build path.
I think problem is with your antivirus..
ReplyDeleteplease disable your antivirus and try again
Thanks Nilesh for solution.
DeleteI am using Avast antivirus. When I disable antivirus, it works.
--------------Issue is Resolved------------------
ReplyDeleteI am Using Avast Antivirus.
@ security -> Antivirus -> Mail shield
Mail Shield is in running status. when I stopped. My program starts working.
Thanks............
The Best Casino Bonuses (2021) | Mapyro
ReplyDeleteFind the best 대전광역 출장안마 casino bonus codes and try the 부산광역 출장안마 best no deposit bonus in 사천 출장샵 Best No 당진 출장샵 Deposit Casino Bonuses 하남 출장샵 (2021)