Meaningless Drivel is fun!*
The moose likes Other JSE/JEE APIs and the fly likes JavaMail AuthenticationFailedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail AuthenticationFailedException" Watch "JavaMail AuthenticationFailedException" New topic
Author

JavaMail AuthenticationFailedException

Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
hi everyone,

I'm having trouble getting my JavaMail to work.

My code is



The error I get is

javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException


Both my username and password fields are correct.
What is wrong?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Bron Czimes:
hi everyone,

I'm having trouble getting my JavaMail to work.

My code is

The error I get is

javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException


Both my username and password fields are correct.
What is wrong?


Try this it works for me

import java.util.*;
import java.io.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


public class MailClient
{
private static final String SMTP_MAIL="smtp";
private String smtpHost = "smtp.blabla.co.om",
user = "", //Proxy login & password... This can be empty ("") ;
password = "";


public MailClient( String smtpHost,String user, String password)
{
this.smtpHost = smtpHost;
this.user = user;
this.password = password;
}


private void sendMsg( String from, String subject, String message,String[] toAddress,String[] attachments ) throws Exception
{


Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);



Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(from));
newMessage.setSubject(subject);


Object content = message;
String debugText = "Subject: " + subject;
log("Sending Text message (" + debugText + ")");
newMessage.setText((String)content);


// Send Message
try
{
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(smtpHost, user, password);
transport.sendMessage(newMessage, getInternetAddress(toAddress) );
}
catch (Exception e )
{
log(e.toString());
}
}

private InternetAddress[] getInternetAddress( String[] toAddresses ) throws Exception
{
InternetAddress[] inetAddr = null;
try
{
inetAddr = new InternetAddress[toAddresses.length + 1];
for ( int i=0;i< toAddresses.length;i++ )
{
inetAddr[i] = new InternetAddress(toAddresses[i]);
}
}
catch (Exception e )
{
log(e.toString());
}
return inetAddr;
}

private void log(String s)
{
System.out.println(new Date() + " " + s);
}
}


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JavaMail AuthenticationFailedException