tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daxin Zuo" <>
Subject RE: Authentication problem in Sending email from servlet. (tomcate 5)
Date Fri, 14 Jan 2005 19:25:04 GMT
Sorry, no problem. The account password is wrong.

-----Original Message-----
From: Daxin Zuo []
Sent: Thursday, January 13, 2005 3:44 PM
To: Tomcat Users List
Subject: Authentication problem in Sending email from servlet. (tomcate

   In my web page, user sends email with attachment, so upload is related. I
load the file in a byte array, and try to send with JavaMail(I know there is
Mail api in Tomcat-Common. But I have no a good example).

 The related code is copied at the end.
 The email serve needs no user-name and password, because the C++ program
sends email without authentication.

 if I set prop.put("mail.smtp.auth", "false");
 Exception: SendEmail Error: javax.mail.AuthenticationFailedException

 If I set to Password and username to "", or set the user name to the
From-Email address:
SendEmail Error: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0
Authentication required

Please tell me what's wrong. Thanks.

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

  Properties prop = System.getProperties();
  prop.put("", szServer);
  prop.put("mail.smtp.from", strFrom);
  prop.put("mail.transport.protocol", "SMTP");
  final String user = tool.isnull2(szAccount)==""?
				 strFrom:                // From email Address
				 tool.isnull2(szAccount);// Account of the user.
  final String pwd = tool.isnull2(szPassword);
  Authenticator auth = null;

	prop.put("mail.smtp.auth", "true");
	auth = new Authenticator (){
	  public PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(user, pwd);

  Session ses1=Session.getInstance(prop,auth);

  MimeMessage msg = new MimeMessage(ses1);
  msg.setFrom(new InternetAddress(strFrom));
  String[] Recipts = strRecipts.split(",");
  for( int k=0; k < Recipts.length; k++)
                       new InternetAddress(Recipts[k]));
  if (!tool.isnull(strCcRecipts)){
	Recipts = strCcRecipts.split(",");
	for (int k = 0; k < Recipts.length; k++)
			 new InternetAddress(Recipts[k]));

  msg.setHeader("X-Mailer", "Java Mail");
  MimeBodyPart  messageBodyPart = new MimeBodyPart();
  messageBodyPart.setContent(strBodyText, "text/plain");
  MimeMultipart multipart = new MimeMultipart();

  if (AttacheFileSize > 0) {  // one attache file only.
	messageBodyPart = new MimeBodyPart();
	messageBodyPart.setDataHandler(new DataHandler(
		 ByteArrayOfFile,     // byte[] it holds the file contents
		 myFileMimeType));    //String, mime type of the file

  msg.setSentDate(new Date());

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message