邮件不是从Spring Controller发送的

时间:2014-11-03 12:48:49

标签: java spring email servlets


org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [servlet-web] in context with path [/xxx] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException] with root cause
java.lang.ClassNotFoundException: javax.mail.MessagingException

这是在浏览器中抛出内部服务器错误,并且没有使用javax api发送邮件。

使用代码的简单java文件:

EmailSender emailSender = new EmailSender();
emailSender.setDefaultProperties();
emailSender.sendEmail(EmailSender.USERNAME, EmailSender.PASSWORD, EmailSender.FROM, "vkeerocks@gmail.com", "Test Mail", "<b> Hi there!!! </b>");

但如果我放入控制器然后抛出错误也一样。

这是我的控制器代码:

@RequestMapping(value = {"register"}, method = {RequestMethod.PUT}, consumes = "application/json", produces = "application/json")
public
@ResponseBody User registerUser(@RequestBody User user, HttpServletResponse response)
{


    if (logger.isDebugEnabled())
    {
        logger.debug("Serving request for registering user: " + user.toString());
    }

    boolean success;
    try
    {

        logger.warn("Registering user : " + user.toString());

        this.userService.insertUser(this.convertUserToUserDto(user));

        EmailSender emailSender = new EmailSender();
        emailSender.setDefaultProperties();
        emailSender.sendEmail(EmailSender.USERNAME, EmailSender.PASSWORD, EmailSender.FROM, "vkeerocks@gmail.com", "Test Mail", "<b> Hi there!!! </b>");

        success = true;

    } catch (Exception e)
    {
        logger.error("While serving the request for registering user :", e);
        success = false;
    }

    return user;

}

0 个答案:

没有答案