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

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

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 中文顯示問題,已設big5但還是亂碼,solaris系統
chialin0216





發文: 4
積分: 0
於 2014-02-14 10:11 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
程式內容是為了讀檔案,然後依檔案內容發送給不同寄件者與mail內容
程式內容如下,有人可以幫忙解答嗎??謝謝了
String fromLang = "BIG5";
String strSubject;

//讀入檔案
String inFile = "sendcontent.txt";

try{
File readfile = new File(inFile);
if (readfile.exists())
{
System.setProperty( "mail.mime.charset", "big5" );
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);

BufferedReader input = new BufferedReader(new FileReader(readfile));
String strContent;

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Create a multipar message
Multipart multipart = new MimeMultipart();

while ((strContent = input.readLine()) != null)
{
while (!strContent.equals("END") && strContent != null)
{
String[] strArry = strContent.split(":");
//收件者
if (strArry[0].equals("TO"))
{
// Set To: header field of the header.
to = strArry[1];
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
}
//主旨、寄件者
else if (strArry[0].equals("SUBJECT"))
{
// Set From: header field of the header.
InternetAddress from = new InternetAddress(fromAdd, fromName, fromLang);
message.setFrom(from);

// Set Subject: header field
message.setSubject(strArry[1], "big5");
//message.setSubject(MimeUtility.encodeText(strArry[1], "big5", "B"));
//message.setHeader("Subject", MimeUtility.encodeText(strArry[1], "big5", "B"));
//message.setSubject(MimeUtility.encodeText(message.getSubject(), "big5", "B"));
System.out.println(strArry[1]);
}
//本文內容
else if (strArry[0].equals("TEXT"))
{
messageBodyPart = new MimeBodyPart();
//* Send the actual HTML message, as big as you like(HTML)
StringBuffer mailText = new StringBuffer("");
mailText.append(strArry[1]);
messageBodyPart.setContent(mailText.toString(), "text/html;charset=BIG5");
multipart.addBodyPart(messageBodyPart);
}
//附件
else if (strArry[0].equals("ATTFILE"))
{
messageBodyPart = new MimeBodyPart();
String filename = strArry[1];
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(MimeUtility.encodeText(filename,"BIG5","B"));
multipart.addBodyPart(messageBodyPart);
}
strContent = input.readLine();
}
message.setContent(multipart);
// Send message
Transport.send(message);
message = new MimeMessage(session);
multipart = new MimeMultipart();
}
System.out.println("END結束");
}
}catch (MessagingException mex) {
mex.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2694 中文顯示問題,已設big5但還是亂碼,solaris系統 chialin0216 5026 2014-02-14 10:11
2503 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 jimwayne 38 2014-02-14 11:22
2518 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 chialin0216 17 2014-02-14 11:24
2499 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 jimwayne 91 2014-02-14 11:46
2496 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 chialin0216 57 2014-02-14 13:33
2462 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 jimwayne 187 2014-02-14 14:27
2488 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 roytsang 5203 2014-02-14 14:11
2537 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 chialin0216 215 2014-02-14 15:18
2534 Re:中文顯示問題,已設big5但還是亂碼,solaris系統 ycpu 116 2014-03-26 23:29
» JWorld@TW »  EJB / 其它Java EE 討論區 » JavaMail

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