我在使用spring webapp发送电子邮件时遇到问题。我正在使用spring mvc。
我有邮件配置类:
@Configuration
class MailConfig {
@Bean(name="mailSender")
public MailSender javaMailService() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost("smtp.gmail.com");
javaMailSender.setPort(587);
javaMailSender.setProtocol("smtp");
javaMailSender.setUsername("email@gmail.com");
javaMailSender.setPassword("password");
Properties mailProperties = new Properties();
mailProperties.put("mail.smtp.auth", "true");
mailProperties.put("mail.smtp.starttls.enable", "starttls");
mailProperties.put("mail.smtp.debug", "true");
javaMailSender.setJavaMailProperties(mailProperties);
return javaMailSender;
}
}
在控制器中我有mailSender
的自动装配实例,我发送这样的电子邮件:
@Autowired
MailSender mailSender;
@RequestMapping(path="emailTest", method = {RequestMethod.GET})
public void emailTest(){
SimpleMailMessage smm = new SimpleMailMessage();
smm.setFrom("email@gmail.com");
smm.setTo("email@gmail.com");
smm.setSubject("title");
smm.setText("text");
mailSender.send(smm);
}
当我尝试发送时,我得到了
HTTP Status 500 - Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/sun/mail/util/MessageRemovedIOException