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);
}
}
Thanks a lot it helped.
The code is just cool……..
hi how are u?
thnx dude,
com.sun.net.ssl. is already deprecated in JDK 1.6
How do we go around this?
All the best,
rocky
Thanks !
Thanks dude,
Ur program help me alot.
Iam also searching for the same.
U reduced my time of development.
Thanks a lot dude….
i have the interest to learn java…
pls send this kind of codings to j.smijith@gmail.com
Thanks!!
Keep up the good work
Thank’s dude
thank’s friend
thanks works very well
Hi Folks. Thanks for your sharing
thanx a lot..:)
thanx very much
it relly works
please tell any books that provides all the basics for this
Hi thanks,
this code helps me a lot….
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.
i solved this error,
thanks friend
Thanks good one!!!
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,
very very thanku…..you did a superb job,thanks alot…
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
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
Thanks dude,
Ur program help me alot.
Iam also searching for the same.
Thank u very much..this information is really very useful to all the java developers.
Hey how can we modified this code to add attachments?
your coding is super…..
hi
the code is working properly with gmail
but when i am trying to use yahoo or some other mailid it is not working
even after changing the host name as
private static final String SMTP_HOST_NAME = “smtp.yahoo.com”
it is showing exception 530 authentication required
very nice….thks a lot!!!!you just come to save my live 🙂
Thanks for the code…it helped a lot!
It really worked yr…Thanx alot
Greetings! Very helpful advice in this particular post! It’s
the little changes that will make the most significant changes.
Many thanks for sharing!
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!
thank you so much. wonderfull
Works like a champ!
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!
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!