我被卡住了。请帮我解决它的例外情况。我还使用此方法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);
}