wordpress做网站怎么样,加工网线,行业网站开发管理软件,局机关建设网站的意义一:邮箱发送原理
1:狂神图解 张三通过smtp协议连接到Smtp服务器#xff0c;然后发送一封邮件给网易的邮件服务器网易分析发现需要去QQ的邮件服务器#xff0c;通过Smtp协议将邮件转投给QQ的Smtp服务器QQ将接收到的邮件存储在456789qq.com这个邮件账号的空间中李四通过Pop3协…一:邮箱发送原理
1:狂神图解 张三通过smtp协议连接到Smtp服务器然后发送一封邮件给网易的邮件服务器网易分析发现需要去QQ的邮件服务器通过Smtp协议将邮件转投给QQ的Smtp服务器QQ将接收到的邮件存储在456789qq.com这个邮件账号的空间中李四通过Pop3协议连接到Pop3服务器收取邮件从456789qq.com这个邮件账号的空间中取出邮件Pop3服务器将取出来的邮件送道李四手中
2:自我理解
我们在qq邮箱上申请一个账号我们发送邮件的时候首先是先发送到qq的邮箱服务器中,每个邮箱服务器中又包含不同功能的邮箱服务器那么专门发送邮件的是SMTP邮箱服务器专门接收文件的是Pop3服务器。那么邮件是通过邮箱服务器中SMTP发送给目标地址的Pop3服务器。邮件服务器就是一个供在网上存储邮件的空间。一般每个邮件服务器的提供商都有自己的邮件服务器只要你申请了他的邮箱账号你就会在他的邮件服务器上拥有自己邮箱。像Google腾讯都是邮件服务的提供商他们都有自己的邮件服务器如果你申请了Gamil邮箱那么在Google的邮件服务器上面你就有自己的一块存储空间了。同样如果你申请了qq邮箱那么在qq邮件服务器上面也有你自己的空间了也就是你的邮箱。当你要收取信件的时候你就需要连接到不同的服务器上面。不同的邮件服务提供商他们的邮件服务器的地址是不一样的。
二:springboot上代码演示
1:导入相关的依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-mail/artifactIdversion2.1.5.RELEASE/version
/dependency
!-- thymeleaf模板依赖 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependency2:在application.properties配置mail
# 访问邮箱的域名 smtp表示协议
spring.mail.hostsmtp.qq.com
spring.mail.username*******qq.com
#授权码
spring.mail.password***********
spring.mail.protocolsmtps
# 采用ssl安全连接
spring.mail.properties.mail.smtp.ssl.enabletrue
3:编写工具类
Component
public class MailClient {Autowiredprivate JavaMailSender mailSender;Value(${spring.mail.username})private String from;public void sendMail(String to, String subject, String content) {try {MimeMessage message mailSender.createMimeMessage();MimeMessageHelper helper new MimeMessageHelper(message);helper.setFrom(from);helper.setTo(to);helper.setSubject(subject);//第二个参数为true表示邮件正文是html格式的默认是falsehelper.setText(content, true);mailSender.send(helper.getMimeMessage());} catch (MessagingException e) {e.getMessage();}}}
4:测试
Autowiredprivate MailClient mailClient;Autowiredprivate TemplateEngine templateEngine;Testvoid textMailSend() {mailClient.sendMail(2231678004qq.com,Text,wyj);}Testvoid textMailSend2() {
// Context context new Context();Context context new Context();//设置前端获取的变量context.setVariable(username, 晓峰我是你媳妇 如花);//第一个参数为templates目录下的要发送html文件的相对路径String content templateEngine.process(/mail/demo, context);System.out.println(content);for (int i 0; i 20; i)mailClient.sendMail(1561962503qq.com, 老公, content);}
要发送的html页面
!DOCTYPE html
html langen xmlns:thhttp://www.thymeleaf.org
headmeta charsetUTF-8titleTitle/title
/head
bodyh1Welcome,span stylecolor: aqua th:text${username}/span/h1
/body
/html