請各位幫我看看javamail的問題(本不應在這裡提這類問題,但在csdn實在沒人幫我解答)
控制檯輸出如下:
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需要認證)
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需要認證)
相關文章
- 請幫我看看呼叫webservice的問題謝謝!Web
- 請高人幫我看看webwork使用Validator驗證的問題Web
- 板橋及各位高手,幫我看看遠端呼叫這個難題,非常感謝。
- 請高手幫忙了,關於javamail的問題JavaAI
- 各位高手來幫我看看sql的問題吧,謝謝啦,線上等答案啊SQL
- 誰能幫我看下哪裡有問題?
- 各位大哥,幫忙解決一下這個問題
- 請大家幫我分析一下這個畢業設計題目是不是有問題?
- 透過知識星球提問時,請大家在提出的問題裡附加上這些資訊
- 這個jsp程式除錯不透過,請各位熱心人幫助解答.JS除錯
- 關於在jb2005整合jboss 開發ejb的問題,前輩們幫忙看看這個問題
- model 與modelform屬性對應問題,誰幫幫我啊ORM
- synchronized關鍵字問題?各位高手,幫幫忙!synchronized
- 用過XMLHTTP的朋友幫幫忙,我這個點選後沒反應XMLHTTP
- 各位高手幫下,亂碼問題
- 用過javamail的朋友幫幫忙,我真的沒有辦法了?!!!JavaAI
- 求各位前輩幫忙看看連表查詢字首問題
- 一個執行緒的問題。請大俠進來幫幫忙看看執行緒
- jf6.2初學者問題,請大家幫忙看看
- (1.5年 測試經驗) 關於簡歷,請各位幫我看看。
- 各位,問個我昨天面試的問題。面試
- 各位大哥,jboss配置資料來源的問題,幫幫忙!
- 初學news例子的一個問題,不知道原因,高手幫我看看
- 大神幫我看個C函式的問題函式
- 在csdn中沒得到解決,到這來碰碰運氣!(問題其實很簡單的)
- 實在是解決不了,請各位高手幫忙
- chatGPT幫助開發實戰解答問題和反思ChatGPT
- 郵件傳送程式,用到了模版模式,幫我看看有啥問題。模式
- 各位高手幫幫忙吧!servlet多執行緒問題,詳細內容請進!!!Servlet執行緒
- 關於分散式異構系統的問題!請幫忙看看分散式
- 安裝JPETSTORE出錯,請幫忙看看是哪出了問題.
- jboss4和mysql5出現問題,請幫我解決MySql
- Jbuilder 問題,請大俠幫忙!!!UI
- 問一個基礎問題,幫我理解一下概念
- 幫我看看如何解決?
- 在dom裡使用getXmlEncoding()出現異常請幫忙看看XMLEncoding
- 請問各位,你們在實際專案中都是採用什麼方式處理登陸這個功能的,非常感謝?banq老師幫幫忙:)
- 這樣提問,大牛才會為你解答(提問的智慧)