com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required (#5.7.1)

Errors:

DEBUG SMTP: use8bit false
MAIL FROM:<nitingautam@……com>
530 authentication required (#5.7.1)
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required (#5.7.1)

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)
    at javax.mail.Transport.send0(Transport.java:151)
    at javax.mail.Transport.send(Transport.java:80)
    at practical.Mailer.main(Mailer.java:37)
QUIT
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required (#5.7.1)

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)
    at javax.mail.Transport.send0(Transport.java:151)
    at javax.mail.Transport.send(Transport.java:80)
    at practical.Mailer.main(Mailer.java:37)
 

 It requires session authentication

Working Code 

package practical;

import java.security.Security;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class GoogleTest {

private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_PORT = "465";
private static final String emailMsgTxt = "Test Message Contents";
private static final String emailSubjectTxt = "A test from gmail";
private static final String emailFromAddress = "something@gmail.com";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
private static final String[] sendTo = {"someone@gmail.com"};

public static void main(String args[]) throws Exception {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

new GoogleTest().sendSSLMessage(sendTo, emailSubjectTxt,
emailMsgTxt, emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
}

public void sendSSLMessage(String recipients[], String subject,
String message, String from) throws MessagingException {
boolean debug = true;

Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("something@gmail.com", "pass");
}
});

session.setDebug(debug);

Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
}

This entry was posted in Java, Troubleshoot. Bookmark the permalink.

37 Responses to com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required (#5.7.1)

  1. Abhijit says:

    Thanks a lot it helped.
    The code is just cool……..

  2. san says:

    hi how are u?

  3. Jatin says:

    thnx dude,

  4. Rocky Castaneda says:

    com.sun.net.ssl. is already deprecated in JDK 1.6

    How do we go around this?

    All the best,

    rocky

  5. saurabh says:

    Thanks !

  6. Meerasaaheb says:

    Thanks dude,
    Ur program help me alot.
    Iam also searching for the same.
    U reduced my time of development.

  7. Smijith says:

    Thanks a lot dude….
    i have the interest to learn java…
    pls send this kind of codings to j.smijith@gmail.com

  8. Twisha says:

    Thanks!!
    Keep up the good work

  9. raghuveer says:

    Thank’s dude

  10. thrivikram says:

    thank’s friend

  11. Leon says:

    thanks works very well

  12. Umanath says:

    Hi Folks. Thanks for your sharing

  13. shiv says:

    thanx a lot..:)

  14. bhasker says:

    thanx very much
    it relly works
    please tell any books that provides all the basics for this

  15. christina says:

    Hi thanks,
    this code helps me a lot….

  16. Ajay says:

    Hello friends,
    when i run this code i got following error:
    Exception in thread “main” javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at readexcel.GoogleTest.sendSSLMessage(GoogleTest.java:75)
    at readexcel.GoogleTest.main(GoogleTest.java:32)

    Pls suggest me if anybody know the solution.

  17. Ajay says:

    i solved this error,
    thanks friend

  18. sneha says:

    Thanks good one!!!

  19. rafi says:

    I could not get this code working.
    I don’t know whether because my company might have the smtp port blocked by SonicWALL or some problem.

    It kept on giving me the error : Connection refused : connect.

    regards,

  20. akjdg says:

    very very thanku…..you did a superb job,thanks alot…

  21. new york books says:

    I think this is among the most vital information for me. And i’m glad reading your article. But should remark on few general things, The website style is great, the articles is really excellent : D. Good job, cheers

  22. Harviston says:

    Undeniably believe that which you stated. Your favorite reason seemed to be on the web the easiest thing to be aware of. I say to you, I certainly get annoyed while people think about worries that they just do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  23. Lokesh says:

    Thanks dude,
    Ur program help me alot.
    Iam also searching for the same.

  24. shivendra says:

    Thank u very much..this information is really very useful to all the java developers.

  25. shivendra says:

    Hey how can we modified this code to add attachments?

  26. raj says:

    your coding is super…..

  27. vinod says:

    hi
    the code is working properly with gmail
    but when i am trying to use yahoo or some other mailid it is not working

  28. vinod says:

    even after changing the host name as
    private static final String SMTP_HOST_NAME = “smtp.yahoo.com”
    it is showing exception 530 authentication required

  29. very nice….thks a lot!!!!you just come to save my live ­čÖé

  30. Shubhendu Chakraborty says:

    Thanks for the code…it helped a lot!

  31. Happy says:

    It really worked yr…Thanx alot

  32. online slots says:

    Greetings! Very helpful advice in this particular post! It’s
    the little changes that will make the most significant changes.
    Many thanks for sharing!

  33. Alexander says:

    Hey there would you mind sharing which blog platform you’re working with?
    I’m planning to start my own blog soon but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most
    blogs and I’m looking for something unique.
    P.S Apologies for being off-topic but I had to ask!

  34. adI says:

    thank you so much. wonderfull

  35. Jose Martinez says:

    Works like a champ!

  36. It’s a shame you don’t have a donate button!
    I’d most certainly donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS
    feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group.

    Talk soon!

  37. My brother suggested I might like this website. He was once entirely right.
    This submit truly made my day. You can not consider just how much time
    I had spent for this information! Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *