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: 7bitThe 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--

解决方案 »

  1.   

    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》[email protected]《/value》   《/property》   《property name="from"》    《value》[email protected]《/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");      }  }}
      

  2.   

    我用java application测试是成功的,但是加入到tomcat里面就不行了,所有的配置和代码都跟测试工程是一样的,只不过是用web 容器来实现监听,请问哪位遇到过这种问题呢?在下急求,谢谢.应该不是quartz的问题,因为邮件时可以收到的,但就是有上面的问题,我在想是不是tomcat的问题?
      

  3.   

    我今天也遇到了这个问题,我在windows下测试是可以正常发送的,但是到linux下面就遇到了你说的这种情况。
    不知道啥原因。调查中。