Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem In JavaMail

  Asked By: Harry    Date: Sep 23    Category: Java    Views: 760
  

I want to send a simple email useing JavaMail. But unfortunately I receive an exception like this:
javax.mail.MessagingException: 530 authentication required


public static void main(String[] args) {
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
Session s = Session.getInstance(props);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("abc@...");
message.setFrom(from);
InternetAddress to = new InternetAddress("abc@...");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");

Transport transport = s.getTransport("smtp");
transport.connect("smtp.mail.yahoo.com", "abc", "*********");
transport.send(message);

//store.close();
}catch(Exception e){
e.printStackTrace();
}
}

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Josephine Gomez     Answered On: Sep 23

I assume you have pop3 access to your yahoo mailbox (else you will get 535 authorization failed if you have not paid for pop access); further you must force your Tranport implementation class to do the authentication and use the alternative state remembering send  method. I edited your snipet in the proper way for it:

Furthermore, in real applications, this way of plain authentication is quite of no use due to security issues. Javamail lets you implement your own transport where you can deploy sasll authentication mechanisms and implement MD5-Digest based authentications too.


public static void main(String[] args) {
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
// props.put("mail.debug", "true"); if you like to see what is going on
props.put("mail.smtp.auth","true"); // to force the authentication
Session s = Session.getInstance(props);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("abc@...");
message.setFrom(from);
InternetAddress to = new InternetAddress("abc@...");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");

Transport transport = s.getTransport("smtp");
transport.connect("smtp.mail.yahoo.com", "abc", "*********");
transport.send(message);

transport.sendMessage(message, message.getAllRecipients());
//store.close();
}catch(Exception e){
e.printStackTrace();
}
}

 
Answer #2    Answered By: Aadi Martin     Answered On: Sep 23

The mail  server needs SMTP authentication, use another mail server that enables SMTP without authentication. I think yahoo is not a good choice. you can test your mail server by using outlook before using JavaMail.

 
Answer #3    Answered By: Jawwad Akram     Answered On: Sep 23

You are trying to use Yahoo smtp to send  the message.
That is not allowed. I think your ISP may have
provided you the required email  and smtp server name
for sending the mail.

 
Didn't find what you were looking for? Find more on Problem In JavaMail Or get search suggestion and latest updates.




Tagged: