当前位置:   article > 正文

Spring-Boot 综合项目实战——个人博客系统-简单邮件管理功能_springboot综合项目实践--个人博客系统

springboot综合项目实践--个人博客系统

目录

学习目标

一.了解博客系统的邮件功能和文件组织结构

二.熟悉博客系统的邮件发送逻辑和页面编写

三.熟悉邮件管理上的一些限制条件设计

四.掌握邮件管理功能的实现

系统开发及运行环境

全局配置文件编写

邮件管理功能

前提

1.邮件管理首页

2.发送纯文本邮件功能

3.发送图片邮件功能

4.发送附件邮件功能

5.发送模板邮件功能


学习目标

一.了解博客系统的邮件功能和文件组织结构

什么是博客系统?

一个典型的博客系统主要包含以下功能模块:

1、用户注册和登录模块

此模块的功能包括新用户的注册,已注册用户的登录。用户需要登录博客系统才能进行

相关操作,否则只能浏览和评论。如果不是博客系统的用户,需要先行注册。

2、博客主页面显示模块

功能是根据用户的设定将博客内容显示给用户,这些内容包括用户的文章及相关评论,

川户的个性化信息以及其他信息导航栏日。

3、文章管理模块

此模块功能包括新增(保存)文章,修改(保存)功能、删除文章功能等。

4、页面显示定制模块

功能包括显示风格定制和显示栏目定制。页面显示风格包括页面版式布局,背景、主题

风格等。显示栏目定制是指设在页面中的显示栏目,如最近文章列表,Logo 等及它们的位

置。

5、用户信息维护模块

修改维护用户的个性化信息,如昵称、签名等。

二.熟悉博客系统的邮件发送逻辑和页面编写

首先我们先了解邮件的协议

1.SMTP协议:全称为 Simple Mail Transfer Protocol,简单邮件传输协议。它定义了邮件客户端软件和SMTP邮件服务器之间,以及两台SMTP邮件服务器之间的通信规则。
2.POP3协议:全称为 Post Office Protocol,邮局协议。它定义了邮件客户端软件和POP3邮件服务器的通信规则。
3.IMAP协议:全称为 Internet Message Access Protocol,Internet消息访问协议,它是对POP3协议的一种扩展,也是定义了邮件客户端软件和IMAP邮件服务器的通信规则。

三.熟悉邮件管理上的一些限制条件设计

如邮箱格式正确与否;邮件的主题是否填写;字数是否超额;附件格式正确与否等等一系列规则。

四.掌握邮件管理功能的实现

系统开发及运行环境

操作系统:windows

Java开发包:JDK8

项目管理工具:Maven 3.9.2

项目开发工具:IntelliJ IDEA

数据库:MySQL

缓存管理工具:Redis

全局配置文件编写

我们需要把该准备的全局配置文件配置好

application.yml

application-jdbc.properties

application-mail.properties 

application-redis.properties 

邮件管理功能

前提

要想实现邮件的管理与发送,我们还需准备以下几个控制类才能完成

EmailMapper

  1. package com.itheima.dao;
  2. import com.itheima.model.domain.ScheduleEmail;
  3. import org.apache.ibatis.annotations.*;
  4. import java.util.List;
  5. /**
  6. * 邮件管理
  7. */
  8. @Mapper
  9. public interface EmailMapper {
  10. // 创建定时邮件
  11. @Insert("INSERT INTO t_schedule_email(toaddress, schedule, subject,content,status,error,create_time) VALUES(#{toaddress}, #{schedule}, #{subject},#{content},#{status},#{error},#{createTime})")
  12. @Options(useGeneratedKeys = true, keyProperty = "id")
  13. public int insertScheduledEmail(ScheduleEmail email);
  14. @Select("select * from t_schedule_email where status='0' and schedule>=#{schedule}")
  15. public List<ScheduleEmail> queryScheduledEmail(@Param("schedule") int schedule);
  16. @Update("update t_schedule_email set status=#{status} where id=#{id}")
  17. public void updateScheduledEmailStatus(@Param("id") int id,@Param("status") String status);
  18. @Update("update t_schedule_email set status=#{status},error=#{error} where id=#{id}")
  19. public void updateScheduledEmailStatusWithError(@Param("id") int id,@Param("status") String status, @Param("error") String error);
  20. }

ScheduleEmail

  1. package com.itheima.model.domain;
  2. import java.util.Date;
  3. public class ScheduleEmail {
  4. private int id;
  5. private String toaddress;
  6. private int schedule;
  7. private String subject;
  8. private String content;
  9. private String status;
  10. private String error;
  11. private Date createTime;
  12. public ScheduleEmail(){}
  13. public ScheduleEmail(String toaddress, int schedule, String subject, String content, String status, String error, Date createTime) {
  14. this.toaddress = toaddress;
  15. this.schedule = schedule;
  16. this.subject = subject;
  17. this.content = content;
  18. this.status = status;
  19. this.error = error;
  20. this.createTime = createTime;
  21. }
  22. public int getId() {
  23. return id;
  24. }
  25. public void setId(int id) {
  26. this.id = id;
  27. }
  28. public String getToaddress() {
  29. return toaddress;
  30. }
  31. public void setToaddress(String toaddress) {
  32. this.toaddress = toaddress;
  33. }
  34. public int getSchedule() {
  35. return schedule;
  36. }
  37. public void setSchedule(int schedule) {
  38. this.schedule = schedule;
  39. }
  40. public String getSubject() {
  41. return subject;
  42. }
  43. public void setSubject(String subject) {
  44. this.subject = subject;
  45. }
  46. public String getContent() {
  47. return content;
  48. }
  49. public void setContent(String content) {
  50. this.content = content;
  51. }
  52. public String getStatus() {
  53. return status;
  54. }
  55. public void setStatus(String status) {
  56. this.status = status;
  57. }
  58. public String getError() {
  59. return error;
  60. }
  61. public void setError(String error) {
  62. this.error = error;
  63. }
  64. public Date getCreateTime() {
  65. return createTime;
  66. }
  67. public void setCreateTime(Date createTime) {
  68. this.createTime = createTime;
  69. }
  70. }

EmailServiceImpl

  1. package com.itheima.service.impl;
  2. import com.itheima.dao.EmailMapper;
  3. import com.itheima.dao.StatisticMapper;
  4. import com.itheima.model.domain.ScheduleEmail;
  5. import com.itheima.service.IEmailService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.mail.MailException;
  9. import org.springframework.mail.SimpleMailMessage;
  10. import org.springframework.mail.javamail.JavaMailSender;
  11. import org.springframework.scheduling.annotation.Scheduled;
  12. import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
  13. import org.springframework.scheduling.support.CronTrigger;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import javax.annotation.PostConstruc
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/967667
推荐阅读
相关标签
  

闽ICP备14008679号