Spring mail发送的邮件无主题,无收件人,附件不显示?

jl6250 2010-01-25 10:50:54
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--

...全文
239 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hty68024352 2011-10-24
  • 打赏
  • 举报
回复
我今天也遇到了这个问题,我在windows下测试是可以正常发送的,但是到linux下面就遇到了你说的这种情况。
不知道啥原因。调查中。
up2pu 2010-01-25
  • 打赏
  • 举报
回复
帮顶一下
牛叔 2010-01-25
  • 打赏
  • 举报
回复
我不会的只能友情帮顶。。。
希望有人给你解决
jl6250 2010-01-25
  • 打赏
  • 举报
回复
我用java application测试是成功的,但是加入到tomcat里面就不行了,所有的配置和代码都跟测试工程是一样的,只不过是用web 容器来实现监听,请问哪位遇到过这种问题呢?在下急求,谢谢.应该不是quartz的问题,因为邮件时可以收到的,但就是有上面的问题,我在想是不是tomcat的问题?
道光2008 2010-01-25
  • 打赏
  • 举报
回复




import org.springframework.mail.MailException;

import org.springframework.mail.MailSender;

import org.springframework.mail.SimpleMailMessage;



public class SendMail {

private MailSender mailSender;

private SimpleMailMessage mailMessage;



public SendMail() {



}



public SimpleMailMessage getMailMessage() {

return mailMessage;

}

public void setMailMessage(SimpleMailMessage mailMessage) {

this.mailMessage = mailMessage;

}

public MailSender getMailSender() {

return mailSender;

}

public void setMailSender(MailSender mailSender) {

this.mailSender = mailSender;

}



public void sendMail() {

SimpleMailMessage message = new SimpleMailMessage(mailMessage);

//设置email内容,

message.setText("Hello 我是杨占辉.这是一个用Spring发送的测试邮件.");



try {

mailSender.send(message);

} catch (MailException e) {

// TODO Auto-generated catch block

System.out.println("O . 发送Email失败了.");

e.printStackTrace();

}

}

}



2.在applicationContext.xml中进行相应的如下配置:



《!-- ******************************** 以下为邮件自动发送示例的配置 ********************************** --》



《!-- mailSender --》

《bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"》

《property name="host"》

《value》smtp.163.com《/value》

《/property》

《property name="javaMailProperties"》

《props》

《prop key="mail.smtp.auth"》true《/prop》《!-- 如果要使用用户名和密码验证,这一步需要 --》

《prop key="mail.smtp.timeout"》25000《/prop》

《/props》

《/property》

《property name="username"》

《value》yangzhanhui《/value》

《/property》

《property name="password"》

《value》yangzhanhui《/value》

《/property》

《/bean》



《!-- 简单的message --》

《bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"》

《property name="to"》

《value》yangzhanhui@neusoft.com《/value》

《/property》

《property name="from"》

《value》yangzhanhui@163.com《/value》

《/property》

《property name="subject"》 《!-- Email 标题 --》

《value》你好,朋友.《/value》

《/property》

《/bean》



《!-- sendMail --》

《bean id="sendMail" class="cn.ssh.struts.util.SendMail"》

《property name="mailMessage"》

《ref bean="mailMessage"/》

《/property》

《property name="mailSender"》

《ref bean="mailSender"/》

《/property》

《/bean》



3.在Action中调用邮件自动发送业务,代码如下:



public class UserAction extends Action {

/*

* Generated Methods

*/



private User user;



private UserService userService;



private SendMail sendMail;



/**

* @return the sendMail

*/

public SendMail getSendMail() {

return sendMail;

}



/**

* @param sendMail the sendMail to set

*/

public void setSendMail(SendMail sendMail) {

this.sendMail = sendMail;

}



public User getUser() {

return user;

}



public void setUser(User user) {

this.user = user;

}



public UserService getUserService() {

return userService;

}



public void setUserService(UserService userService) {

this.userService = userService;

}



/**

* Method execute

*

* @param mapping

* @param form

* @param request

* @param response

* @return ActionForward

*/

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

UserForm userForm = (UserForm) form;



user.setUsername(userForm.getUsername());

user.setPassword(userForm.getPassword());



if (userService.login(user)) {



sendMail.sendMail();

return mapping.findForward("success");



} else {



return mapping.findForward("fail");



}





}

}

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧