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

一份完整的网站策划书刷关键词怎么刷

一份完整的网站策划书,刷关键词怎么刷,广告设计公司介绍文案,如何查看网站名称SpringBoot实现发送邮箱 引言 在现代应用程序中,电子邮件通常是不可或缺的一部分。在Spring Boot中,你可以轻松地实现发送不同类型的邮件,包括文本、带附件和HTML邮件。本博客将向你展示如何使用Spring Boot发送这些不同类型的电子邮件。 步…

SpringBoot实现发送邮箱

在这里插入图片描述

引言

在现代应用程序中,电子邮件通常是不可或缺的一部分。在Spring Boot中,你可以轻松地实现发送不同类型的邮件,包括文本、带附件和HTML邮件。本博客将向你展示如何使用Spring Boot发送这些不同类型的电子邮件。

步骤一:导入依赖

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

步骤二:配置邮箱信息

mail:# 邮件 SMTP 服务器的主机名host: smtp.qq.com# 用于登录 SMTP 服务器的邮箱地址username: 1111111@qq.com# 用于登录 SMTP 服务器的邮箱密码或授权码password: abcdefghijklmnopqrstuvwxyz# SMTP 服务器的端口port: 587# 是否启用 SMTP 认证,通常应设置为 truesmtpAuth: true# 是否启用 STARTTLS 安全传输协议,通常应设置为 truesmtpStarttlsEnable: true# 是否要求使用 STARTTLS 安全传输协议,通常应设置为 truesmtpStarttlsRequired: true# 默认编码defaultEncoding: UTF-8

步骤三:邮箱配置类

@Data
//配置属性文件
@Component
//说明配置文件属性的头部
@ConfigurationProperties(prefix = "mail")
public class MailConfig {private String host;private String username;private String password;private Integer port;private String smtpAuth;private String smtpStarttlsEnable;private String smtpStarttlsRequired;private String defaultEncoding;@Beanpublic JavaMailSender javaMailSender() {//邮箱发送对象JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();javaMailSender.setHost(host);javaMailSender.setPort(port);javaMailSender.setUsername(username);javaMailSender.setPassword(password);javaMailSender.setDefaultEncoding(defaultEncoding);// 配置其他属性,如协议、调试等,根据需要Properties properties = new Properties();properties.setProperty("mail.smtp.auth", smtpAuth);properties.setProperty("mail.smtp.starttls.enable", smtpStarttlsEnable);properties.setProperty("mail.smtp.starttls.required", smtpStarttlsRequired);javaMailSender.setJavaMailProperties(properties);return javaMailSender;}
}

步骤四:创建邮箱工具类

这里的发送人必须设置不然会报异常:501 Mail from address must be same as authorization user.

@Component
public class MailUtils {@Value("${mail.username}")private String username;@Resourceprivate JavaMailSender javaMailSender;/*** 邮箱发送** @param to      收信人* @param title   邮箱标题* @param content 邮箱内容*/public void sendMail(String to, String title, String content) {//邮箱消息对象SimpleMailMessage simpleMailMessage = new SimpleMailMessage();simpleMailMessage.setFrom(username);//发送人simpleMailMessage.setTo(to);//收件人simpleMailMessage.setSubject(title);//邮箱标题simpleMailMessage.setText(content);//邮箱内容//实现发送邮箱javaMailSender.send(simpleMailMessage);}/*** 群发邮箱** @param toList  收信人集合* @param title   邮箱标题* @param content 邮箱内容*/public void sendEmailToMultipleRecipients(List<String> toList, String title, String content) {SimpleMailMessage message = new SimpleMailMessage();message.setFrom(username);//发送人message.setTo(toList.toArray(new String[0]));message.setSubject(title);message.setText(content);javaMailSender.send(message);}/*** 发送HTML邮箱** @param to       收信人* @param title    邮箱标题* @param text     HTML内容* @param filePath 文件路径* @throws MessagingException 邮箱异常*/public void sendEmailWithAttachment(String to, String title, String text, String filePath) throws MessagingException {MimeMessage message = javaMailSender.createMimeMessage();message.setFrom(username);//发送人MimeMessageHelper helper = new MimeMessageHelper(message, true);helper.setTo(to);helper.setSubject(title);helper.setText(text);FileSystemResource file = new FileSystemResource(new File(filePath));helper.addAttachment(FileUtil.getName(filePath), file);javaMailSender.send(message);}/*** 发送HTML邮箱** @param to    收信人* @param title 邮箱标题* @param text  HTML内容* @param file  文件* @throws MessagingException 邮箱异常*/public void sendEmailWithAttachment(String to, String title, String text, File file) throws MessagingException {MimeMessage message = javaMailSender.createMimeMessage();message.setFrom(username);//发送人MimeMessageHelper helper = new MimeMessageHelper(message, true);helper.setTo(to);helper.setSubject(title);helper.setText(text);helper.addAttachment(FileUtil.getName(file), file);javaMailSender.send(message);}/*** 发送HTML邮箱** @param to          收信人* @param title       邮箱标题* @param htmlContent HTML内容* @throws MessagingException 邮箱异常*/public void sendHtmlEmail(String to, String title, String htmlContent) throws MessagingException {MimeMessage message = javaMailSender.createMimeMessage();message.setFrom(username);//发送人MimeMessageHelper helper = new MimeMessageHelper(message, true);helper.setTo(to);helper.setSubject(title);helper.setText(htmlContent, true); // 设置为true表示HTML内容javaMailSender.send(message);}
}

通过使用Spring Boot和JavaMailSender,你可以轻松地实现发送文本、带附件和HTML邮件的功能。这些示例可以帮助你在你的应用程序中集成邮件发送功能,以便满足不同类型的邮件需求

http://www.mmbaike.com/news/55355.html

相关文章:

  • 广州可以做票务商城的网站公司免费行情软件网站下载
  • 做漆包线的招聘网站如何推广seo
  • 扒人家网站做网站最新国际新闻头条今日国际大事件
  • c 网站模板外链官网
  • 毕设做购物网站系统的原因互联网营销顾问是做什么的
  • 网站用户黏度如何优化关键词的方法
  • 新开传奇网站首区营销方案范文
  • 网站开发神器网络优化工具app手机版
  • seo优化的网站抖音seo优化公司
  • 网站制作前景怎么样西安seo搜推宝
  • 如何创建自己的公司网站河南疫情最新消息
  • 山西省政府网站建设的公司写手接单平台
  • 更加重视政府门户网站建设站长工具网站排名
  • 做网站哪个软件好用seo培训学什么
  • 东莞企业网站建设重庆百度seo排名优化软件
  • 2018年企业网站优化应该怎么做全国各城市疫情搜索高峰进度
  • 凡科做网站的方法百度云登陆首页
  • 官网做得好的公司正规网络公司关键词排名优化
  • 正版全平台内容系统排名优化软件点击
  • 企业开源建站系统互联网营销师报名
  • 网站开发建设一般多少钱搜索引擎优化的流程
  • 新建网站软件推广互联网推广
  • 庐江网站制作公司球队排名榜实时排名
  • 做的网站无法显示此页网络营销推广方案论文
  • 找生意做那个网站靠谱友情链接管理系统
  • 怎么做网站卖机床中视频自媒体账号注册下载
  • 做视频网站用什么语言河南seo技术教程
  • 宝安龙华积分商城网站建设电商网站上信息资源的特点包括
  • 企业做网站的费用百度网站ip地址
  • typecho wordpress关键词优化案例