Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sending mail with Digest-MD5 authentication. AuthenticationFailedException

843785Jul 10 2008 — edited Jul 31 2008
Hello,

I am having this problem if which part of my code is wrong, I already checked a lot of forums and in googles and nothing happens. And why do i keep on receiving javax.mail.AuthenticationFailedException. I am actually testing this on localhost. I am using Digest-Md5 authentication type, and my server is configured correctly. the username and password are also correct.
I know that i have to set sasl.realm as well (but I am confused which one should is effective to use: .props.put() or tr.setSASLRealm()).

String auth_realm="host.net";
String auth_user = "myuser";
String auth_password="mypassword";
String smtp_add= "smtphost";
String smtp_port = "25";
String to = "recepient@host.net";

Properties props = new Properties();
props.put("mail.smtp.host",smtp_add);
props.put("mail.smtp.port",smtp_port);
props.put("mail.smtp.auth",true);
props.put("mail.trasport.protocol","smtp");
props.setProperty("mail.smtp.quitwait", "false");

props.put("mail.smtp.sasl.realm",auth_realm);       //MD5-Digest

Session session = Session.getInstance(props);

Message msg = new MimeMessage(session);
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("test");
msg.setSentDate(new Date());
msg.setText("hello");

Transport tr = session.getTransport("smtp");

if(email_auth.equals("DIGEST-MD5")){
  if (tr instanceof SMTPTransport) {
      ((SMTPTransport) tr).setSASLRealm(auth_realm);   // i also use props.put("mail.smtp.sasl.realm",auth_realm); 
     }
  }

tr.connect(smtp_add,smtp_port,auth_user,auth_password); 
                                    
msg.saveChanges();
                    
 tr.sendMessage(msg,msg.getAllRecipients());
tr.close();
Please advice if anybody here has an idea. I really need ur help

Thank you

quince

Edited by: quincex on Jul 30, 2008 9:26 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2008
Added on Jul 10 2008
3 comments
882 views