mailSender.send(mimeMessagePreparators);
MimeMessagePreparator mimeMessagePreparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws MessagingException {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
// get the subscribers of the attachment and put them as the recipients
// of this email
mimeMessageHelper.setTo(subscribers);
// all email have the same from, bcc, reply to, subject, and body
String fromEmailAddress = emailTemplate.getFromEmailAddress();
mimeMessageHelper.setFrom(fromEmailAddress);
// note: bcc the sender so that they get the email too
mimeMessageHelper.setBcc(fromEmailAddress);
// this will help on auto replies and bounce messages
// also it should help on deliverability
mimeMessageHelper.setReplyTo(fromEmailAddress);
String subject = emailTemplate.getSubject();
mimeMessageHelper.setSubject(subject);
String emailBody = emailTemplate.getBody();
mimeMessageHelper.setText(OPEN_EMAIL_TAGS + emailBody + CLOSE_EMAIL_TAGS, true);
// get the physical file and add as an email attachment
FileSystemResource file = new FileSystemResource(new File(directory, attachment.getName()));
mimeMessageHelper.addAttachment(attachment.getName(), file);
}
};
我需要知道哪些电子邮件失败(即有一个MailException)并最终告诉用户与失败的电子邮件相关联的附件的名称。如何从异常中检索附件名称?到目前为止,我已经
try {
mailSender.send(mimeMessagePreparators);
} catch (MailSendException mailSendException) {
Map<Object, Exception> map = mailSendException.getFailedMessages();
for (Map.Entry<Object, Exception> entry : map.entrySet()) {
MimeMessage mimeMessage = (MimeMessage) entry.getKey();
// get attachment names from mimeMessage? or preferably
// get in a more simplistic way using a helper such as MimeMessageHelper
} catch (MailException mailException) {
// how do I get attachment names here?
}
如果您有一堆MimeMessage对象,请参阅从下面开始的JavaMail FAQ条目:
本质上,您需要迭代消息中的部分,确定哪些部分代表附件,然后访问您认为代表附件“名称”的部分中的任何元数据或头。
我创建了简单的MailService来通过电子邮件发送内容。它工作但我不知道如何处理异常(我的想法是在HTML视图中打印一些信息或在404页重定向) 邮件服务: 在控制器中的用法:
我试着做 但返回的资源不包含任何属性。 我怎么才能正确地做这件事呢?
我写了下面的代码: 但不幸的是,它给了我以下例外: servlet com.google.appengine.api.files中出现未捕获的异常。com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImple.java:597)中的FinalizationException位于com.goole
当我使用JavaMailSender发送带有附件的电子邮件时,它总是失败,并引发以下异常: 这是我的密码
web.xml 应用程序-servlet.xml context.xml(在tomcat conf文件夹中) 谢谢你的建议和帮助。
问题内容: 是否可以通过使用列的索引来获取列名?我浏览了API文档,但找不到任何东西。 问题答案: 你可以从元数据中获取此信息。参见 例如 你可以从那里获取列名称。如果你这样做 然后也会为你获取检索到的标签名称。