請各位幫我看看javamail的問題(本不應在這裡提這類問題,但在csdn實在沒人幫我解答)

rtm發表於2003-09-17
控制檯輸出如下:

DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.21cn.com", port 25
220 21cn.com SMTP Server of AIMC 2.9.5.2 (E).
DEBUG SMTP: connected to host "smtp.21cn.com", port: 25
EHLO rtm
250-21cn.com, helo (DELAYED)
250-EXPN
250-HELP
250-8BITMIME
250-AUTH=LOGIN PLAIN
250-AUTH LOGIN PLAIN
250 XTMD
DEBUG SMTP: Found extension "EXPN", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "XTMD", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
cnRtbXRy
334 UGFzc3dvcmQ6
eGlhb2Zlbmc=
235 OK Authenticated
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.AuthenticationFailedException

程式如下:
package mail;

import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
import java.util.Properties;

public class MailSend {
public static void main(String[] args) {
Properties prop = new Properties();
prop.put("mail.transport.default", "smtp");
prop.put("mail.debug", "true");
prop.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(prop,null);
MimeMessage message = new MimeMessage(session);
try{
message.setContent("send mail test..", "text/plain");
message.setText("hehe");
message.setFrom(new InternetAddress("rtmmtr@21cn.com"));
message.setRecipient(Message.RecipientType.TO,new InternetAddress("a2602435@163.net"));
message.setSubject("mail test by rtm");
}catch(MessagingException mE){
System.err.println(mE.toString());
}
Transport transport = null;
try{
transport = session.getTransport("smtp");
}catch(NoSuchProviderException nspE){
System.err.println(nspE.toString());
}
try{
transport.connect("smtp.21cn.com", "rtmmtr", "");
transport.send(message);
transport.close();
}catch(MessagingException mE){
System.out.println(mE.toString());
}
}
}

請各位大哥指點(這裡我把密碼隱掉了,21cn需要認證)

相關文章