当前位置: 首页 > news >正文

excel如何做超链接网站全网网络营销推广

excel如何做超链接网站,全网网络营销推广,柳州旅游网站建设,广州电子商务网站建设文章目录前言环境、版本等pom依赖引入springboot项目配置文件获取邮箱授权码配置properties文件定义接口信息接收类编写邮件发送服务类编写接口swagger测试1、简单邮件发送2、html格式发送(支持附件)前言 最近再看xxl-job的源码,其中在邮件告警通知中使用到了告警信…

文章目录

  • 前言
  • 环境、版本等
  • pom依赖引入
  • springboot项目配置文件
    • 获取邮箱授权码
    • 配置properties文件
  • 定义接口信息接收类
  • 编写邮件发送服务类
  • 编写接口
  • swagger测试
    • 1、简单邮件发送
    • 2、html格式发送(支持附件)

前言

最近再看xxl-job的源码,其中在邮件告警通知中使用到了告警信息邮件通知的方式,挺有意思的,特写一篇文章进行简单的配置和使用。

环境、版本等

  • springboot 2.1.4.RELEASE
  • jdk 1.8

pom依赖引入

springboot的版本就已经对mail组件进行了控制,只需要引入对应的依赖即可,无需单独设置版本。(也可以设定指定的版本号)

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId>
</dependency>

springboot项目配置文件

由于加入了spring-boot-starter-mail依赖组件,此时如果需要使用mail功能,还需要进行下面的几项配置。

获取邮箱授权码

进入QQ邮箱的设置,找到账户
在这里插入图片描述
账户项中下滑至POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
在这里插入图片描述

选择生成授权码。需要发送确认短信信息,当发送成功后,将会获得当前邮箱的授权码信息
将授权码信息复制粘贴到spring.mail.password中即可!

配置properties文件

创建application.properties文件,并在其中配置如下信息:

server.port=80spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=302592372@qq.com
spring.mail.from=302592372@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.socketFactory.class=javax.net.ssl.SSLSocketFactory

定义接口信息接收类

主要是接口传递参数使用,如下结构:

import lombok.Data;
import java.io.Serializable;@Data
public class MailRequest implements Serializable {/*** 接收人*/private String sendTo;/*** 邮件主题*/private String subject;/*** 邮件内容*/private String text;/*** 附件路径*/private String filePath;}

编写邮件发送服务类

编写邮件发送操作的服务类,使用两种方式:简单邮件内容发送html邮件内容发送

import cn.xj.emails.uo.MailRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.Date;@Slf4j
@Service
public class SendMailService {@Autowiredprivate JavaMailSender javaMailSender;@Value("${spring.mail.from}")private String sendMailer;/*** 简单邮件内容发送* @param mailRequest*/public void sendSimpleMail(MailRequest mailRequest) {SimpleMailMessage message = new SimpleMailMessage();//邮件发件人message.setFrom(sendMailer);//邮件收件人 1或多个message.setTo(mailRequest.getSendTo().split(","));//邮件主题message.setSubject(mailRequest.getSubject());//邮件内容message.setText(mailRequest.getText());//邮件发送时间message.setSentDate(new Date());javaMailSender.send(message);log.info("发送邮件成功:{}->{}",sendMailer,mailRequest.getSendTo());}/*** Html格式邮件,可带附件* @param mailRequest*/public void sendHtmlMail(MailRequest mailRequest) {MimeMessage message = javaMailSender.createMimeMessage();try {MimeMessageHelper helper = new MimeMessageHelper(message,true);//邮件发件人helper.setFrom(sendMailer);//邮件收件人 1或多个helper.setTo(mailRequest.getSendTo().split(","));//邮件主题helper.setSubject(mailRequest.getSubject());//邮件内容helper.setText(mailRequest.getText(),true);//邮件发送时间helper.setSentDate(new Date());String filePath = mailRequest.getFilePath();if (StringUtils.hasText(filePath)) {FileSystemResource file = new FileSystemResource(new File(filePath));String fileName = filePath.substring(filePath.lastIndexOf(File.separator));helper.addAttachment(fileName,file);}javaMailSender.send(message);log.info("发送邮件成功:{}->{}",sendMailer,mailRequest.getSendTo());} catch (MessagingException e) {log.error("发送邮件时发生异常!",e);}}
}

编写接口

制定一个测试 controller,进行简单的接口开发。

import cn.xj.emails.service.SendMailService;
import cn.xj.emails.uo.MailRequest;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/email")
@Api(value = "发送邮件接口",tags = {"发送邮件接口"})
public class TestController {@Autowiredprivate SendMailService sendMailService;@PostMapping("/simple")public void SendSimpleMessage(@RequestBody MailRequest mailRequest) {sendMailService.sendSimpleMail(mailRequest);}@PostMapping("/html")public void SendHtmlMessage(@RequestBody MailRequest mailRequest) { sendMailService.sendHtmlMail(mailRequest);}
}

swagger测试

为了测试的方便,项目中整合了swagger2进行接口测试,当然也可以使用postman等工具。

1、简单邮件发送

/email/simple

在这里插入图片描述
收到邮件如下:
在这里插入图片描述

2、html格式发送(支持附件)

/email/html

在这里插入图片描述
收到的邮件如下所示:
在这里插入图片描述

http://www.hkea.cn/news/392754/

相关文章:

  • 贵阳天柱网站建设招聘域名注册平台有哪些
  • 网站建设电话营销百度问一问官网
  • 网站优化建设河南怎么关闭seo综合查询
  • 自贡做响应式网站开发公司google搜索引擎入口google
  • 东莞哪种网站推广好微信朋友圈推广文案
  • 现在学做网站赚钱吗东莞市优速网络科技有限公司
  • 宁津做网站公司宣传推广图片
  • 陕西的建设厅官方网站数据分析报告
  • 企业网站建设的定位互联网
  • 注册域名之后如何做网站优化清理大师
  • wordpress+在线播放推广seo网站
  • 丽水网站建设明恩玉杰网站开发框架
  • 如何设计网站中的上传功能搜索引擎技术基础
  • 余江区建设局网站百度搜索引擎优化的方法
  • 做网站用c 还是java万网域名注册教程
  • 青岛做网站那家好专业的网站优化公司排名
  • 网站如何做淘宝推广seo服务 收费
  • 学完js了可以做哪些网站营业推广的形式包括
  • 网站会员系统怎么做模版seo是指什么职位
  • 上海集团网站制作新闻 近期大事件
  • 商城网站验收标准seo关键词排名优化怎样收费
  • 睢宁做网站公司珠海百度关键字优化
  • 临安市住房和建设局网站伊春seo
  • 天津百度做网站多少钱游戏代理平台哪个好
  • b2b模式的网站google网站
  • 做优化网站哪个公司好十大营销策略
  • 软件商店app苏州网站关键词优化推广
  • wordpress添加日历首页优化公司
  • 日本可以自己做网站吗查询网站服务器
  • 做网站维护的人叫啥友情链接交换工具