Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

Transport.send gives a javax.mail.AuthenticationFailedException from a JSP

843830Jul 3 2002 — edited Jul 8 2002
Hello all,
My Java skills are decaffeinated so accept my apologies in advance. I have code that works perfectly as an application but I tried to turn it into a .jsp and now the mail portion of it does not work. The problem lies within the "Transport.send( msg );" call. When I comment this out the page finishes as it should (without sending mail of course). Otherwise, I get this message, "Sending failed; nested exception is: javax.mail.AuthenticationFailedException". I am only sending to our SMTP server and, remember, this works outside of a jsp so I don't actually believe it is an authentication problem. Our admin doesn't believe it is either.


public boolean SendEmail( String fromUser, String toUser ){
int optind, count = 0;
String to = "MNDarius@company.domain"; //toUser,
String subject = "Document added to " + lastFolder;
String cc = null, bcc = null, url = null;
String mailhost="xxxxx.YYYYY.ZZZZZ.company.domain";
String mailer="SendEmail";
String protocol=null, host=null, password=null, user=null;
String record=null; // name of folder in which to record mail
boolean debug = false;

//Other Declarations
Vector eAddrVector = new Vector();
String emailStrObj = new String();

emailStrObj = (String) to;
emailStrObj.trim();
StringTokenizer st=new StringTokenizer(emailStrObj,";",false );

err1 = emailStrObj;

while( st.hasMoreTokens() ){
eAddrVector.add( count, st.nextToken() );

try{
if( to == null ){
to = "mndarius@company.domain";
subject = "ERROR: No 'To:' information";
err.writeLog( "'To:' contained no value, substituted default" );
}

Properties props = System.getProperties();

if( mailhost != null ){
err3 = (String)props.put("mail.smtp.host",mailhost );
}

// Get a Session object
Session session = Session.getDefaultInstance( props, null );

if( debug )
session.setDebug( true );

// construct the message
Message msg = new MimeMessage( session );

if( fromUser == null ){
//msg.setFrom( new InternetAddress( fromUser ) );
msg.setFrom(new InternetAddres("MNDarius@company.domain"));
}
else
msg.setFrom(new InternetAddress("MNDarius@company.domain"));

msg.setRecipients( Message.RecipientType.TO,
InternetAddress.parse((String)eAddrVector.elementAt(count), false));

if( cc != null )
msg.setRecipient(Message.RecipientType.CC,InternetAddress.parse (cc,false));
if( bcc != null )
msg.setRecipients( Message.RecipientType.BCC,InternetAddress.parse( bcc, false ) );

msg.setSubject( subject );

msg.setHeader( "X-Mailer", mailer );
msg.setSentDate( new Date() );

//***********************************************
// The problem lies within the Transport.send( msg );
// or maybe its settings?
//***************************************************
Transport.send( msg );

}//End 'try'

catch( SendFailedException sfe ){
err.writeLog( sfe.getMessage() );
sfeErr = sfe.getMessage();
return false;
}

catch( IllegalWriteException iwe ){
iweErr = iwe.getMessage();
return false;
}

catch( MessagingException me ){
meErr = me.getMessage();
return false;
}

catch( Exception e ){
err.writeLog( e.getMessage() );
eErr = e.getMessage();
return false;
}//End 'catch'

count += 1;

}//End while-loop

return true;

}//End class 'SendEmail'
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2002
Added on Jul 3 2002
1 comment
356 views