Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Harry Hunter   on Sep 23 In Java Category.

  
Question Answered By: Josephine Gomez   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();
}
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

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


Tagged: