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..........!

Comments

  1. have you added required jars for programme in java build path.

    ReplyDelete
    Replies
    1. Thanks for your reply.
      But, I have 'javaee.jar' and 'mail.jar' in java build path.

      Delete
  2. I think problem is with your antivirus..
    please disable your antivirus and try again

    ReplyDelete
    Replies
    1. Thanks Nilesh for solution.
      I am using Avast antivirus. When I disable antivirus, it works.

      Delete
  3. --------------Issue is Resolved------------------
    I am Using Avast Antivirus.
    @ security -> Antivirus -> Mail shield
    Mail Shield is in running status. when I stopped. My program starts working.
    Thanks............

    ReplyDelete
  4. The Best Casino Bonuses (2021) | Mapyro
    Find the best 대전광역 출장안마 casino bonus codes and try the 부산광역 출장안마 best no deposit bonus in 사천 출장샵 Best No 당진 출장샵 Deposit Casino Bonuses 하남 출장샵 (2021)

    ReplyDelete

Post a Comment

Popular posts from this blog

SOLVED :- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Bresenham line drawing algorithm in java

dda line drawing algorithm in java