org.springframework.mail.MailAuthenticationException:身份验证失败;嵌套异常是javax.mail.AuthenticationFailedException

时间:2016-01-30 09:36:17

标签: java spring email spring-mvc

我被卡住了。请帮我解决它的例外情况。我还使用此方法helper.setFrom("here i have a question.?")

配置为不太安全和我传递的内容

这是我的dispatcher-servlet.xml

<bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="587" />
    <property name="username" value="skent.qc@gmail.com" />
    <property name="password" value="password" />

    <!-- The name of the property, following JavaBean naming conventions -->
    <property name="javaMailProperties">
        <props>
            <prop key="mail.transport.protocol">smtp</prop>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.debug">true</prop>
        </props>
    </property>

这是我的web.xml文件

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>    

这是我的Java文件,我必须从中发送邮件:

try {
    MimeMessage mimeMessage = mailSender.createMimeMessage();
    FileSystemResource file = new FileSystemResource(HomeAppUtil.getPathForImage() + "/Invoice_" + tblInvoice.getInvoiceId() + ".pdf");

    log.debug("this is sendEmail method in ProviderServiceImpl class 4");

    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "utf-8");

    helper.setTo(emailId);  
    helper.setSubject(subject);
    helper.setText(message, message);
    helper.addAttachment(file.getFilename(), file);
    System.out.println(file.toString());

    mailSender.send(mimeMessage);
    System.out.println("message send success");
}
catch (Exception e) {
    log.debug("Error message "+e);
}

0 个答案:

没有答案