赞
踩
目录
什么是博客系统?
一个典型的博客系统主要包含以下功能模块:
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
- package com.itheima.dao;
-
- import com.itheima.model.domain.ScheduleEmail;
- import org.apache.ibatis.annotations.*;
-
- import java.util.List;
-
- /**
- * 邮件管理
- */
- @Mapper
- public interface EmailMapper {
-
- // 创建定时邮件
- @Insert("INSERT INTO t_schedule_email(toaddress, schedule, subject,content,status,error,create_time) VALUES(#{toaddress}, #{schedule}, #{subject},#{content},#{status},#{error},#{createTime})")
- @Options(useGeneratedKeys = true, keyProperty = "id")
- public int insertScheduledEmail(ScheduleEmail email);
-
-
- @Select("select * from t_schedule_email where status='0' and schedule>=#{schedule}")
- public List<ScheduleEmail> queryScheduledEmail(@Param("schedule") int schedule);
-
- @Update("update t_schedule_email set status=#{status} where id=#{id}")
- public void updateScheduledEmailStatus(@Param("id") int id,@Param("status") String status);
-
- @Update("update t_schedule_email set status=#{status},error=#{error} where id=#{id}")
- public void updateScheduledEmailStatusWithError(@Param("id") int id,@Param("status") String status, @Param("error") String error);
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
ScheduleEmail
- package com.itheima.model.domain;
-
- import java.util.Date;
-
-
- public class ScheduleEmail {
- private int id;
- private String toaddress;
- private int schedule;
- private String subject;
- private String content;
- private String status;
- private String error;
- private Date createTime;
- public ScheduleEmail(){}
- public ScheduleEmail(String toaddress, int schedule, String subject, String content, String status, String error, Date createTime) {
- this.toaddress = toaddress;
- this.schedule = schedule;
- this.subject = subject;
- this.content = content;
- this.status = status;
- this.error = error;
- this.createTime = createTime;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getToaddress() {
- return toaddress;
- }
- public void setToaddress(String toaddress) {
- this.toaddress = toaddress;
- }
- public int getSchedule() {
- return schedule;
- }
- public void setSchedule(int schedule) {
- this.schedule = schedule;
- }
- public String getSubject() {
- return subject;
- }
- public void setSubject(String subject) {
- this.subject = subject;
- }
- public String getContent() {
- return content;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public String getStatus() {
- return status;
- }
- public void setStatus(String status) {
- this.status = status;
- }
- public String getError() {
- return error;
- }
- public void setError(String error) {
- this.error = error;
- }
- public Date getCreateTime() {
- return createTime;
- }
- public void setCreateTime(Date createTime) {
- this.createTime = createTime;
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
EmailServiceImpl
- package com.itheima.service.impl;
-
- import com.itheima.dao.EmailMapper;
- import com.itheima.dao.StatisticMapper;
- import com.itheima.model.domain.ScheduleEmail;
-
-
- import com.itheima.service.IEmailService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.mail.MailException;
- import org.springframework.mail.SimpleMailMessage;
- import org.springframework.mail.javamail.JavaMailSender;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
- import org.springframework.scheduling.support.CronTrigger;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
-
- import javax.annotation.PostConstruc
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。