Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 79778 invoked from network); 14 Jan 2005 19:27:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 14 Jan 2005 19:27:29 -0000 Received: (qmail 33719 invoked by uid 500); 14 Jan 2005 19:27:12 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 33703 invoked by uid 500); 14 Jan 2005 19:27:12 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 33686 invoked by uid 99); 14 Jan 2005 19:27:11 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from vm2-ext.prodigy.net (HELO vm2-ext.prodigy.net) (207.115.63.90) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 14 Jan 2005 11:27:10 -0800 Received: from daxin (63-200-135-134.ded.pacbell.net [63.200.135.134]) (authenticated bits=0) by vm2-ext.prodigy.net (8.12.10 maild auth/8.12.10) with ESMTP id j0EJR6Rq256016 for ; Fri, 14 Jan 2005 14:27:06 -0500 From: "Daxin Zuo" To: "Tomcat Users List" Subject: RE: Authentication problem in Sending email from servlet. (tomcate 5) Date: Fri, 14 Jan 2005 11:25:04 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Importance: Normal X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Sorry, no problem. The account password is wrong. -----Original Message----- From: Daxin Zuo [mailto:dzuo@techexcel.com] Sent: Thursday, January 13, 2005 3:44 PM To: Tomcat Users List Subject: Authentication problem in Sending email from servlet. (tomcate 5) Hi, 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.*; import org.apache.commons.net.smtp.*; import org.apache.commons.net.io.Util; .... Properties prop = System.getProperties(); prop.put("mail.smtp.host", 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++) msg.addRecipient(Message.RecipientType.TO, new InternetAddress(Recipts[k])); if (!tool.isnull(strCcRecipts)){ Recipts = strCcRecipts.split(","); for (int k = 0; k < Recipts.length; k++) msg.addRecipient(Message.RecipientType.CC, new InternetAddress(Recipts[k])); } msg.setSubject(strSubject); msg.setHeader("X-Mailer", "Java Mail"); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setDisposition(Part.INLINE); messageBodyPart.setContent(strBodyText, "text/plain"); MimeMultipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); 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 messageBodyPart.setFileName(astrAttach); multipart.addBodyPart(messageBodyPart); } msg.setContent(multipart); msg.setSentDate(new Date()); Transport.send(msg); --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org