JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » EJB / 其它Java EE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 JavaMail 程式發生例外 java.net.SocketException: Connection reset
cowbayal98





發文: 84
積分: 0
於 2010-10-12 18:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟看著書上範例 寫了個程式如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
tring mailServer = "smtp.gmail.com";
    String from = "xxx@gmail.com";
    String to = "xxx@gmail.com";
    
    String title = "這是一封測試信";
    String messageText = "這是一封測試信";
    
    
    try
    {
      // STEP 1 : 設定系統所使用的e-mail伺服器,傳送協定
      Properties props = System.getProperties();
      props.put("mail.host", mailServer);  // e-mail伺服器
      props.put("mail.transport.protoco", "smtp");  // 傳送協定
      
      
      // STEP 2 : 建立處理e-mail寄送工作的session物件 , 不是 HttpSession歐
       Session mailSession= javax.mail.Session.getInstance(props, null);
       mailSession.setDebug(false);  // 設定不取得傳送e-mail時, e-mail的處理訊息
       
       
       // STEP 3 : 建立處理郵件內容的 MimeMessage物件
       MimeMessage msg = new MimeMessage(mailSession);
       msg.setFrom(new InternetAddress(from));  // 設定寄件人e-mail
       msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false));  // 設定收件人e-mail
       msg.setSubject(title); // 設定e-mail的主旨
       msg.setSentDate(new Date());  // 設定時間
       msg.setText(messageText, "UTF-8");
       
       
       // STEP 4 : 傳送信件
       //Transport.send(msg);
       msg.saveChanges();
       Transport transport = mailSession.getTransport("smtp");
       transport.connect("xxx@gmail.com", "xxx");
       transport.sendMessage(msg, msg.getAllRecipients());
       transport.close();
       
       System.out.println("這樣應該有成功吧?");
        
    } catch(AddressException e)
    {
      e.printStackTrace();
    } catch(MessagingException e)
    {
      e.printStackTrace();
    }

透過jsp呼叫這支servlet 寄信 ,
卻發生下列例外 , 讓小弟感到十分困惑 ,
上網搜尋爬文仍不知所以然 ,
懇請前輩給與解決的提示

修改了 mailServer 出現了新的問題 ~"~
感謝提示~來去試試
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 34sm5962598ibi.2
 
  at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
  at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
  at mail.SendMailServlet.doGet(SendMailServlet.java:62)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
  at java.lang.Thread.run(Thread.java:619)
 


cowbayal98 edited on 2010-10-12 21:39
reply to postreply to post
新手上路,煩請指正 = ="
 新手上路,煩請指正 = ="
  新手上路,煩請指正 = ="
話題樹型展開
人氣 標題 作者 字數 發文時間
519 JavaMail 程式發生例外 java.net.SocketException: Connection reset cowbayal98 3290 2010-10-12 18:15
424 Re:JavaMail 程式發生例外 java.net.SocketException: Connection reset koji 75 2010-10-12 20:18
569 Re:JavaMail 程式發生例外 java.net.SocketException: Connection reset cowbayal98 12 2010-10-12 21:51
» JWorld@TW »  EJB / 其它Java EE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8