1.pop.xml
<!– 邮件–> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-mail</artifactid> </dependency> 2.application.properties
#邮件配置: spring.mail.host=smtp.qq.com spring.mail.username=发送人的邮箱@qq.com spring.mail.password=密码(授权码,具体看下面的操作) spring.mail.properties.mail.smtp.auth = true spring.mail.properties.mail.smtp.starttls.enable = true spring.mail.properties.mail.smtp.starttls.required=true spring.mail.properties.mail.smtp.ssl.enable = true
先看看qq邮箱或者其他邮箱pop3服务开了没有。没有的去开启
然后点下面的生成授权码,这个要配置在上面的password那里,不要用你邮箱登录密码去配置!!!
3.测试类,只实现简单的邮件
import org.junit.test; import org.junit.runner.runwith; import org.springframework.beans.factory.annotation.autowired; import org.springframework.boot.test.context.springboottest; import org.springframework.mail.javamail.javamailsender; import org.springframework.mail.javamail.mimemessagehelper; import org.springframework.test.context.junit4.springrunner; import javax.mail.internet.mimemessage; @runwith(springrunner.class) @springboottest public class demoapplicationtests { @autowired javamailsender sender; @test public void sendsimplemail() throws exception { mimemessage message = null; boolean flag = true; try { message = sender.createmimemessage(); mimemessagehelper helper = new mimemessagehelper(message, true); helper.setfrom(“发送人的邮箱@qq.com”); helper.setto(“接受人的邮箱@qq.com”); helper.setsubject(“邮件主题”); helper.settext(“内容”); sender.send(message); } catch (exception e) { flag = false; system.out.println(e); } system.out.println(“flag:” flag); } }
4.接收结果,图片就不马赛克了,不要乱搞哦
如果,你对上面的内容还有疑问,推荐选择西部数码企业云邮箱!有专人协助您解答邮箱疑问。
西部数码企业云邮箱,采用分布式集群架构,数据多份写入,规避单点故障,全球智能中继,更安全稳定。企业邮箱无限空间,极速收发,支持层级子文件夹,邮件撤回,日程微信通知、邮件监管、自定义工作报告功能、邮件归档、ssl部署等几十项功能。而且价格实惠,还可以免费试用!
企业邮箱免费试用入口:https://www.west.cn/services/mail/
如何绑定中文域名 中文域名对企业的作用是什么windows安装临时文件能删吗?域名解析没有生效-云建站/云站群/小程序vps云服务器挂载数据盘net域名一年多少钱 注册net域名怎么样网站设计色彩搭配原理及注意事项【池州网站建设】哪家网站建设公司好?企业购买邮箱哪个好