javamail不能发信,急!!! 测试过的,可以发信。http://www.ideagrace.com/articlecontent.asp?id=34 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 kenvinp(kenvinp) 为什么邮件正文是乱码?? Properties props = new Properties();把这句改成 Properties props = System.getProperties();sendMailSession = Session.getInstance(props, null);把这句改成 sendMailSession = Session.getDefaultInstance(props, null);试一试~~~ kenvinp(kenvinp) ( ) 转换了很多种,都不行??//sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder(); //message.setText("=?GB2312?B?"+enc.encode(tcontent.getBytes())+"?=");//message.setText(MimeUtility.encodeText(tcontent,"gb2312","b")); tcontent=new String(tcontent.getBytes("iso8859_1"),"gbk"); public static String UnicodeToChinese(String s){ try{ if(s==null || s.equals("")) return ""; String newstring=null; newstring = s; newstring = new String(s.getBytes("ISO8859_1"),"gbk"); return newstring; } catch( Exception e) { return s; } } public static String ChineseToUnicode(String s){ try{ if(s==null || s.equals("")) return ""; String newstring=null; newstring=new String(s.getBytes("gb2312"),"ISO8859_1"); return newstring; } catch( Exception e) { return s; } } 懒得查原因了,你看一下我的代码,再试试。 public void sendMailWithAttach(String smtpHost, String senderAddress, String receiverAddress, String mailSubject, String mailContent, String attachmentPath) throws AddressException, MessagingException { Properties props = System.getProperties(); props.put("mail.smtp.host", smtpHost); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(senderAddress)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiverAddress)); message.setSubject(mailSubject); MimeBodyPart messageBodyPart = new MimeBodyPart(); //fill message messageBodyPart.setText(mailContent); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // Part two is attachment messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(attachmentPath); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(attachmentPath); multipart.addBodyPart(messageBodyPart); message.setContent(multipart); Transport.send(message); } 调试信息,收不了附件,显示是乱码。250 OkRCPT TO:<[email protected]>250 OkDEBUG SMTP: Verified AddressesDEBUG SMTP: [email protected]DATA354 End data with <CR><LF>.<CR><LF>Message-ID: <13137441.1119974362296.JavaMail.kevin>Date: Tue, 28 Jun 2005 23:59:22 +0800 (CST)From: [email protected]To: [email protected]Subject: =?GBK?B?dGVzdMu5tdm30rCiyaq24Lf5?=Mime-Version: 1.0------=_Part_2_12812631.1119974364734test斯蒂芬阿瑟多幅------=_Part_2_12812631.1119974364734Content-Disposition: attachment; filename=a1.rarRar! 调试信息,收不了附件,显示是乱码。250 OkRCPT TO:<[email protected]>250 OkDEBUG SMTP: Verified AddressesDEBUG SMTP: [email protected]DATA354 End data with <CR><LF>.<CR><LF>Message-ID: <13137441.1119974362296.JavaMail.kevin>Date: Tue, 28 Jun 2005 23:59:22 +0800 (CST)From: [email protected]To: [email protected]Subject: =?GBK?B?dGVzdMu5tdm30rCiyaq24Lf5?=Mime-Version: 1.0------=_Part_2_12812631.1119974364734test斯蒂芬阿瑟多幅------=_Part_2_12812631.1119974364734Content-Disposition: attachment; filename=a1.rarRar! 会不会是邮件服务器的关系,你换一个服务器(email地址)试试。 求仿百度文库技术 [100分]求 Hibernate Count 的一个问题... Runtime.exec调用外部程序,如何做到不与其产生关联? 大家用过sitemesh的请帮帮忙...被装饰的页面不能再使用<jsp:include/> 请问我用struts2上传文件 spring连接两个数据库问题 SSH框架的搭建 怎样在数据库上实现struts资源文件? 谁知道怎么在eclipse中安装tomcat插件? 急问,!!jar文件!在线等 如何将Form内变量的值赋给JSP页面中的变量? J2EE名词解释
为什么邮件正文是乱码??
把这句改成 Properties props = System.getProperties();sendMailSession = Session.getInstance(props, null);
把这句改成 sendMailSession = Session.getDefaultInstance(props, null);试一试~~~
转换了很多种,都不行??
//sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
//message.setText("=?GB2312?B?"+enc.encode(tcontent.getBytes())+"?=");
//message.setText(MimeUtility.encodeText(tcontent,"gb2312","b"));
tcontent=new String(tcontent.getBytes("iso8859_1"),"gbk");
try{
if(s==null || s.equals("")) return "";
String newstring=null;
newstring = s;
newstring = new String(s.getBytes("ISO8859_1"),"gbk");
return newstring;
}
catch( Exception e)
{
return s;
}
}
public static String ChineseToUnicode(String s){
try{
if(s==null || s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch( Exception e)
{
return s;
}
}
public void sendMailWithAttach(String smtpHost, String senderAddress, String receiverAddress,
String mailSubject, String mailContent, String attachmentPath) throws AddressException, MessagingException {
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(senderAddress));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiverAddress));
message.setSubject(mailSubject); MimeBodyPart messageBodyPart = new MimeBodyPart(); //fill message
messageBodyPart.setText(mailContent); Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart); // Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachmentPath);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(attachmentPath);
multipart.addBodyPart(messageBodyPart); message.setContent(multipart);
Transport.send(message);
}
RCPT TO:<[email protected]>
250 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 End data with <CR><LF>.<CR><LF>
Message-ID: <13137441.1119974362296.JavaMail.kevin>
Date: Tue, 28 Jun 2005 23:59:22 +0800 (CST)
From: [email protected]
To: [email protected]
Subject: =?GBK?B?dGVzdMu5tdm30rCiyaq24Lf5?=
Mime-Version: 1.0------=_Part_2_12812631.1119974364734test斯蒂芬阿瑟多幅
------=_Part_2_12812631.1119974364734
Content-Disposition: attachment; filename=a1.rarRar!
RCPT TO:<[email protected]>
250 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 End data with <CR><LF>.<CR><LF>
Message-ID: <13137441.1119974362296.JavaMail.kevin>
Date: Tue, 28 Jun 2005 23:59:22 +0800 (CST)
From: [email protected]
To: [email protected]
Subject: =?GBK?B?dGVzdMu5tdm30rCiyaq24Lf5?=
Mime-Version: 1.0------=_Part_2_12812631.1119974364734test斯蒂芬阿瑟多幅
------=_Part_2_12812631.1119974364734
Content-Disposition: attachment; filename=a1.rarRar!