java 发送 SimpleMailMessage 时出现“无 MimeMessage 内容”异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33015900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:05:00  来源:igfitidea点击:

"No MimeMessage content" exception when sending SimpleMailMessage

javaspringemailjavamail

提问by Vincent F

I'm trying to send a very simple email with org.springframework.mail.javamail.JavaMailSenderImpl. Below is the code :

我正在尝试使用 org.springframework.mail.javamail.JavaMailSenderImpl 发送一封非常简单的电子邮件。下面是代码:

SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(request.getCustomerEmail());
mailMessage.setSubject("someSubject");
mailMessage.setFrom("[email protected]");
mailSender.send(mailMessage);

This is the exception I get :

这是我得到的例外:

Caused by: org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: No MimeMessage content
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:459)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296)

I really don't understand why this happens..

我真的不明白为什么会发生这种情况..

Any idea ?

任何的想法 ?

回答by Vincent F

After a couple of hours of struggling, I've found that this is all because the mail I'm creating has no text !

经过几个小时的努力,我发现这都是因为我创建的邮件没有文本!

If I add this line, then it works like a charm :

如果我添加这一行,那么它就像一个魅力:

mailMessage.setText("blabla");

I really got confused by the "No MimeMessage content" message.. Does anybody agree that the message could be more informative, or is it only me ? Does this mean we can't send an email with just a subject and no content ?

我真的被“没有 MimeMessage 内容”消息弄糊涂了。有人同意这条消息可以提供更多信息,还是只有我?这是否意味着我们不能发送只有主题而没有内容的电子邮件?