雷丰阳Springboot视频培训教程问题解决记录之十——邮件发送以及java.lang.IllegalStateException: Not in multipart mode错误
2019-04-28 16:30
961 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lswx2006/article/details/89640656
注意事项:为了保证安全,在设置邮箱用户名密码的时候,通常都不是直接使用密码,而是使用授权码。
[code]spring.mail.username=xxx@163.com spring.mail.password=授权码 spring.mail.host=smtp.163.com #当连接失败时,有时需要打开ssl选项 #spring.mail.properties.mail.smtp.ssl.enable=true
163邮箱获取授权码的位置为
java.lang.IllegalStateException: Not in multipart mode - create an appropriate MimeMessageHelper via a constructor that takes a 'multipart' flag if you need to set alternative texts or add inline elements or attachments.
出现此问题的原因是创建helper时第二个参数没有设置,及即multipart模式
[code] @Test public void contextLoads() throws MessagingException { MimeMessage message = mailSender.createMimeMessage(); //出现上述错误是因为创建helper的时候没有设置第二个参数,即multipart模式 MimeMessageHelper helper = new MimeMessageHelper(message, true ); helper.setSubject("测试邮件"); //此选项的第二个参数为是否是HTML邮件 helper.setText("<a href=#>来自MAILDEMO的测试邮件!</a>", true); helper.addAttachment("1.jpg", new File("C:\\Users\\Pictures\\微信图片_20171023155221.jpg")); helper.setTo("XXX@abc.com"); helper.setFrom("XXX@163.com"); mailSender.send(message); }
相关文章推荐
- spring boot 发送邮件带附件出现Not in multipart mode - create an appropriate MimeMessageHelper错误
- 关于SpringBoot :java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader错误解决方法
- 使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决
- 发送邮件时遇到mail包冲突异常Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream 解决方法
- java.lang.Exception: libsvm classes not in CLASSPATH!问题解决方法
- SpringBoot项目创建报:java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication错误的解决方案
- web工程下,用spring包发送邮件,报java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport 错误
- java.sql.SQLException:Unknown column '****' in 'where clause'错误问题原因以及如何解决?
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL问题解决方法
- 【解决】SSH问题(四)Java.Lang.ClassNotFoundException: Org.Springframework.Transaction.TransactionException
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener错误的解决办法
- mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener问题解决
- 邮件发送:java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream错误如何解决
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- 问题解决-java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- spring boot新手教程之使用FastJson解析JSON数据以及解决返回中文乱码问题
- IDEA连接mysql教程,以及出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver的解决办法
- idea调试SpringMvc, 出现:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener错误的解决办法