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

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

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 javamail用pchome寄信失敗><
homwei





發文: 106
積分: 0
於 2010-03-13 21:16 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<%@ page import="javax.mail.*"%>
<%@ page import="javax.activation.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="java.util.*,java.io.*,java.text.*"%>
<%@ page contentType="text/html;charset=Big5"%>
 
<html>
<head>
<title>JavaMail.jsp</title>
</head>
<body>
 
<h2>利用JavaMail來傳送註冊資料</h2>
<%
  
  InternetAddress[] address = null;
  ResourceBundle messages = ResourceBundle.getBundle("Mail");
  
 
  request.setCharacterEncoding("Big5");
 
  
  String mailserver="ecd.pchome.com.tw";
  String From="jsptw@pchome.com.tw";
  String Subject="歡迎加入myapp";
  String name = request.getParameter("Name");
  String password = request.getParameter("Password");
  String to = request.getParameter("To");
 
  Object[] args={name,password};
  MessageFormat formatter=new MessageFormat("");
  formatter.applyPattern(messages.getString("message"));
  String messageText = formatter.format(args);
 
  boolean sessionDebug=false;
 
  try{
    //設定所要用的Mail伺服器和所使用的傳送協定
    java.util.Properties props = System.getProperties();
    props.put("mail.host",mailserver);
    props.put("mail.transport.protocol","smtp");
 
    //產生新的Session服務
    javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(props,null);
    mailSession.setDebug(sessionDebug);
    
 
    Message msg = new MimeMessage(mailSession);
 
    //設定傳送郵件的發信人
    msg.setFrom(new InternetAddress(From));
    
    //設定傳送郵件的收信人的信箱
    address=InternetAddress.parse(to,false);
    msg.setRecipients(Message.RecipientType.TO,address);
 
    //設定主題
    msg.setSubject(Subject);
 
    //設定送信的時間
    msg.setSentDate(new Date());
 
    Multipart mp = new MimeMultipart();
    MimeBodyPart mbp = new MimeBodyPart();
 
    //設定郵件內容的型態為text/html
    mbp.setContent(messageText,"text/html;charset=Big5");
    mp.addBodyPart(mbp);
    msg.setContent(mp);
 
    Transport.send(msg);
    
    out.println("郵件已順利傳送");
  }
  catch(MessagingException mex)
  {
    mex.printStackTrace();
  }
 
%>


我寄給我自已的msn信箱,結果沒寄出,也沒發生錯誤....
還是mailserver過時ecd.pchome.com.tw,我試過用stmp.pchome.com.tw也不行
寄信人帳號我是照書上打的不是我的,可是書上說寄信只要打xxx@pchome.com.tw就可以


reply to postreply to post
作者 Re:javamail用pchome寄信失敗>< [Re:homwei]
ulina





發文: 28
積分: 0
於 2010-03-22 17:35 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
我寄給我自已的msn信箱,結果沒寄出,也沒發生錯誤....
還是mailserver過時ecd.pchome.com.tw,我試過用也不行  stmp  .pchome.com.tw
寄信人帳號我是照書上打的不是我的,可是書上說寄信只要打xxx@pchome.com.tw就可以


會不會是host name打錯了呢
郵件遞送 (SMTP) 伺服器:smtp.pchome.com.tw
‧勾選「外寄(SMTP)郵件伺服器驗證」功能。
‧郵件接收 (POP3) 伺服器:pop3.pchome.com.tw
‧郵件接收方式:POP3


reply to postreply to post
» JWorld@TW »  EJB / 其它Java EE 討論區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8