Java邮件验证错误

问题描述:

我第一次使用Java Mail API,但无法正常工作。我的服务器需要验证,所以我不得不使用它。我不断收到以下错误:Java邮件验证错误

> 250-PIPELINING 250-SIZE 40960000 
> 250-ETRN 250-STARTTLS 250-AUTH PLAIN 
> LOGIN 250-AUTH=PLAIN LOGIN 
> 250-ENHANCEDSTATUSCODES 250 8BITMIME 
> DEBUG SMTP: Found extension 
> "PIPELINING", arg "" DEBUG SMTP: Found 
> extension "SIZE", arg "40960000" DEBUG 
> SMTP: Found extension "ETRN", arg "" 
> DEBUG SMTP: Found extension 
> "STARTTLS", arg "" DEBUG SMTP: Found 
> extension "AUTH", arg "PLAIN LOGIN" 
> DEBUG SMTP: Found extension 
> "AUTH=PLAIN", arg "LOGIN" DEBUG SMTP: 
> Found extension "ENHANCEDSTATUSCODES", 
> arg "" DEBUG SMTP: Found extension 
> "8BITMIME", arg "" DEBUG SMTP: Attempt 
> to authenticate DEBUG SMTP: check 
> mechanisms: LOGIN PLAIN AUTH LOGIN 334 
> Base64text base64text 334 base64text 
> base64text 235 2.7.0 Authentication 
> successful DEBUG: getProvider() 
> returning 
> javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun 
> Microsystems, Inc] DEBUG SMTP: useEhlo 
> true, useAuth true 
> javax.mail.AuthenticationFailedException: 
> failed to connect, no password 
> specified? 
>   at javax.mail.Service.connect(Service.java:329) 
>   at javax.mail.Service.connect(Service.java:176) 
>   at javax.mail.Service.connect(Service.java:125) 
>   at javax.mail.Transport.send0(Transport.java:194) 
>   at javax.mail.Transport.send(Transport.java:124) 
>   at Mailman.main(Mailman.java:61) 

正如你所看到的,我得到一个“验证成功”的消息,但随后它踢我出去的“AuthenticationFailedException。”我难倒...

这里的源的相关部分:

properties.setProperty("mail.smtp.host", host);    
     properties.setProperty("mail.smtp.port", "25"); 


     properties.setProperty("mail.smtp.user", "myemailhere"); 
     properties.setProperty("mail.smtp.password", "mypasshere"); 
     properties.setProperty("mail.smtp.auth", "true");  
     properties.setProperty("mail.debug", "true"); 


     // Get the default Session object. 
     Session session = Session.getDefaultInstance(properties); 

     try{ 
     // Create a default MimeMessage object. 
     MimeMessage message = new MimeMessage(session); 

     // Set From: header field of the header. 
     message.setFrom(new InternetAddress(from)); 

     // Set To: header field of the header. 
     message.addRecipient(Message.RecipientType.TO, 
            new InternetAddress(to)); 

     // Set Subject: header field 
     message.setSubject("This is the Subject Line!"); 

     // Now set the actual message 
     message.setText("This is actual message"); 

     Transport transport = session.getTransport("smtp"); 
      transport.connect(host, 25, "myemailhere", "mypasshere"); 
      message.saveChanges(); 
      Transport.send(message); 



     // Send message 
     Transport.send(message); 
     System.out.println("Sent message successfully...."); 
     }catch (MessagingException mex) { 
     mex.printStackTrace();   
     }  

任何建议,将不胜感激...

我改成了

message.setText("This is actual message"); 

      Transport transport = session.getTransport("smtp"); 
       transport.connect(null,smtpUser,smtpPassword); //host, 25, "myemailhere", "mypasshere"); 
       message.saveChanges(); 
       transport.sendMessage(message,message.getAllRecipients()); 

//    Transport.send(message); 



      // Send message 
      // Transport.send(message); 
      System.out.println("Sent message successfully...."); 

它的工作

+0

我通常不是所有大写的支持者,但是......谢谢!我几个小时都在盯着这件事。你的解决方案就像一个魅力。 – Jeff 2011-04-25 14:10:44

+0

没问题。我找到了Javamail API ......这是慈善术语。这一切都有效,但从a点到b点并不总是很清楚 – MJB 2011-04-25 16:46:24