基于spring boot java 邮箱功能

阅读:1003 2019-03-20 14:09:25 来源:新网

1.pop.xml

org.springframework.bootspring-boot-starter-mail2.application.properties

#邮件配置:spring.mail.host=smtp.qq.comspring.mail.username=发送人的邮箱@qq.comspring.mail.password=密码(授权码,具体看下面的操作)spring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=truespring.mail.properties.mail.smtp.ssl.enable=true

先看看qq邮箱或者其他邮箱pop3服务开了没有。没有的去开启

3.测试类,只实现简单的邮件

importorg.junit.test;importorg.junit.runner.runwith;importorg.springframework.beans.factory.annotation.autowired;importorg.springframework.boot.test.context.springboottest;importorg.springframework.mail.javamail.javamailsender;importorg.springframework.mail.javamail.mimemessagehelper;importorg.springframework.test.context.junit4.springrunner;importjavax.mail.internet.mimemessage;@runwith(springrunner.class)@springboottestpublicclassdemoapplicationtests{@autowiredjavamailsendersender;@testpublicvoidsendsimplemail()throwsexception{mimemessagemessage=null;booleanflag=true;try{message=sender.createmimemessage();mimemessagehelperhelper=newmimemessagehelper(message,true);helper.setfrom("发送人的邮箱@qq.com");helper.setto("接受人的邮箱@qq.com");helper.setsubject("邮件主题");helper.settext("内容");sender.send(message);}catch(exceptione){flag=false;system.out.println(e);}system.out.println("flag:"+flag);}}4.接收结果,图片就不马赛克了,不要乱搞哦

上一篇: java 邮箱发送
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服