Spring mail发送的邮件无主题,无收件人,附件显示在正文中而且是乱码的的问题,我是用quartz定时触发的。哪位遇到过同样的问题,请教!下面附上邮件的内容: ------=_Part_0_16708202.1264148460185
Content-Type: multipart/related; boundary="----=_Part_1_5503135.1264148460247" ------=_Part_1_5503135.1264148460247
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit The attachment is information about Course Report.Please confirm.Thanks.If you have any problem ,free call me.
------=_Part_1_5503135.1264148460247-- ------=_Part_0_16708202.1264148460185
Content-Type: application/octet-stream; name="=?GB18030?Q?=BF=CE=B3=CC=D0=C5=CF=A2.doc?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?GB18030?Q?=BF=CE=B3=CC=D0=C5=CF=A2.doc?="
------=_Part_0_16708202.1264148460185--
Content-Type: multipart/related; boundary="----=_Part_1_5503135.1264148460247" ------=_Part_1_5503135.1264148460247
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit The attachment is information about Course Report.Please confirm.Thanks.If you have any problem ,free call me.
------=_Part_1_5503135.1264148460247-- ------=_Part_0_16708202.1264148460185
Content-Type: application/octet-stream; name="=?GB18030?Q?=BF=CE=B3=CC=D0=C5=CF=A2.doc?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?GB18030?Q?=BF=CE=B3=CC=D0=C5=CF=A2.doc?="
------=_Part_0_16708202.1264148460185--
MimeMessage mim = mailSender.createMimeMessage();
// 发送附件的帮助类
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mim, true, "UTF-8");
helper.setFrom("[email protected]");
helper.setTo("[email protected]"); /* MimeUtility.encodeText----解决中文乱码问题 */
helper.setSubject(MimeUtility.encodeText("课程信息确认报表"));
helper.setText("The attachment is information about Course Report.Please confirm.Thanks.If you have any problem ,free call me.");
String attachName = MimeUtility.encodeText("课程信息.doc"); helper.addAttachment(attachName, new ClassPathResource(
"/email/课程信息.doc").getFile()); mailSender.send(mim);
System.out.println("邮件发送完成!"); } catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
配置文件:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.163.com" />
<property name="port" value="25" />
<property name="username" value="[email protected]" />
<property name="password" value="*********" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>帮忙看看