个人简单的邮箱网站项目(基于SpringBoot环境搭建)

news/2024/5/15 16:54:15/文章来源:https://blog.csdn.net/yuran06/article/details/121609347

目录

一个个人邮箱网站(基于SpringBoot环境搭建)

目前只能达到发送一些简单的内容,如果有啥好的建议可以发评论!!
源码地址在文章最下方
本人还在学习中

优化的地方

  • 可以通过连接数据库来登录用户!

效果

登录前的主界面

在这里插入图片描述

登录界面

在这里插入图片描述

登录后的主界面

在这里插入图片描述

发送邮箱界面

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

项目的概述

1.这个项目目前只能实现固定的发送邮箱,接受者邮箱是可以改变的。

2.目前功能只有发送一些简单的标题、内容这样子后续我会慢慢加点功能上去。

3.这个项目是在网站上实现的,界面布局和效果你们都可以随意按照你们的想法去改。

4.核心的代码主要是在后台这一块,有SpringBoot+SpringSecurity、Springboot+Mybatis、Springboot+thymeleaf、异步任务、Druid。

5.可以实现发送邮件的简单日志,还有一个带附件发送的半成品的一些代码。

核心功能代码

后端

数据库的连接

spring:datasource:username: rootpassword: 123456url: jdbc:mysql://localhost:3306/meweb?serverTimezone=UTC&userUnicode=true&characterEncoding=utf-8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource#下面这一块是一些Durid的设置不设置也是可以的#Spring Boot 默认是不注入这些属性值的,需要自己绑定#druid 数据源专有配置initialSize: 5minIdle: 5maxActive: 20maxWait: 60000timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: falsepoolPreparedStatements: true#配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入#如果允许时报错  java.lang.ClassNotFoundException: org.apache.log4j.Priority#则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4jfilters: stat,wall,log4jmaxPoolPreparedStatementPerConnectionSize: 20useGlobalDataSourceStat: trueconnectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

mybatis配置

# 配置mybatis
# 扫描包的位置
mybatis.type-aliases-package=com.me.pojo
# 实现mapper接口配置mapper和接口的绑定
mybatis.mapper-locations=classpath:mapper/*.xml

邮箱的一些配置

# 邮箱
spring.mail.username=2336164407@qq.com  
# 邮箱密码的明文	
spring.mail.password=xxxxxxxxxx		
# 我使用的是QQ邮箱
spring.mail.host=smtp.qq.com			
# 开启加密验证
spring.mail.properties..mail.smtp.ssl.enable=true  # QQ邮箱独有的加密验证

发送邮箱的业务

// 封装成了一个方法
@Service
public class SendMailService {@AutowiredJavaMailSenderImpl mailSender;@Asyncpublic void sendMail(String subject, String text, String to, String from) {SimpleMailMessage simpleMailMessage = new SimpleMailMessage();simpleMailMessage.setSubject(subject);simpleMailMessage.setText(text);simpleMailMessage.setTo(to);simpleMailMessage.setFrom(from);mailSender.send(simpleMailMessage);}}

用户数据查询代码

mapper层

@Repository
@Mapper
public interface UserInfoMapper {/*** 查找对应用户信息* @param username* @return*/UserInfo getUserInfo(String username);
}

maooer对应xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.me.mapper.UserInfoMapper"><select id="getUserInfo" resultType="UserInfo" parameterType="String">select * from meweb.user where username=#{username};</select></mapper>

Service接口

public interface UserInfoService {/*** 查找对应用户信息* @param username* @return*/UserInfo getUserInfo(String username);
}

Service接口实现类

@Service
public class UserInfoServiceImpl implements UserInfoService {@Autowiredprivate UserInfoMapper userInfoMapper;@Overridepublic UserInfo getUserInfo(String username) {return userInfoMapper.getUserInfo(username);}
}

SpringSecurity这块的功能代码

创建一个类去实现UserDetailsService接口

@Component
public class CustomUserDetailsService implements UserDetailsService {@Autowiredprivate UserInfoService userInfoService;@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {UserInfo userInfo = userInfoService.getUserInfo(username);if(userInfo==null){throw new UsernameNotFoundException("用户不存在");}String role = userInfo.getRole();List<GrantedAuthority> authorities = new ArrayList<>();//角色必须以"ROLE_"做为开头,数据库中不需要!authorities.add(new SimpleGrantedAuthority("ROLE_"+role));return new User(userInfo.getUsername(),//因为数据库是明文,所以我们这里需要加密处理new BCryptPasswordEncoder().encode(userInfo.getPassword()),authorities);}
}
@EnableWebSecurity // 用来开启SpringSecurity的注解
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Autowiredprivate CustomUserDetailsService customUserDetailsService;@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/","index").permitAll()    // permitAll() 这个代表谁都可以访问.antMatchers("/mail/**").hasAnyRole("mail");// hasAnyRole() 这个代表要有指定的角色才可以访问的,比如有mail这个角色// 这一块是用于自定义的登录页面http.formLogin().usernameParameter("username")  // 里面的username必须和前端表单传递的name要一致.passwordParameter("password")	// 里面的password必须和前端表单传递的name要一致.loginPage("/toLogin")			// 设置登录页面的地址.loginProcessingUrl("/login");	// 登录页面表单提交的地址http.csrf().disable();					// 禁用csrfhttp.logout().logoutSuccessUrl("/");	// 设置当注销用户时跳转的页面http.rememberMe().rememberMeParameter("remeber");	// 设置当前用户是否记住我默认保留14天}@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {// 我使用的是通过在代码中硬性设置账号和密码来实现的,如果要通过数据库的来实现账号和密码验证的话可以在网上找找资料!// passwordEncoder()密码加密方式,我这里用到的是 new BCryptPasswordEncoder()加密//方法一通过连接数据库来登录用户auth.userDetailsService(customUserDetailsService).passwordEncoder(new BCryptPasswordEncoder());//方法二把用户名和密码写入内存中/*auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("me").password(new BCryptPasswordEncoder().encode("123456")).roles("mail").and().withUser("admin").password(new BCryptPasswordEncoder().encode("123456")).roles("mail");*/}}

前端

主页面代码

<!DOCTYPE html>
<html lang="zh_cn" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head><meta charset="UTF-8"><link rel="stylesheet" th:href="@{/css/index.css}"><!--这个是用来设置浏览器访问的小图标的--><link rel="icon" th:href="@{/image/1.png}" sizes="16x16"> <script th:src="@{/js/index.js}"></script><title>ME中心</title>
</head>
<body><div id="index">  <div ><h1>欢迎来到ME的零度空间<span id="time" ></span></h1><div><div sec:authorize="!isAuthenticated()"><a th:href="@{/toLogin}" class="zhuxiao" >登录</a></div><div sec:authorize="isAuthenticated()"><a th:href="@{/logout}" class="zhuxiao" >注销</a></div></div><a th:href="@{/mail/mailView}" class="but" style="text-align: center;">发送邮件</a><a th:href="@{/mail/mailView}" class="but" style="text-align: center;">发送带附件的邮件</a><a href="" class="but" style="text-align: center;pointer-events: none;">待开发</a><a href="" class="but" style="text-align: center;pointer-events: none;">待开发</a><a href="" class="but" style="text-align: center;pointer-events: none;">待开发</a><a href="" class="but" style="text-align: center;pointer-events: none;">待开发</a><a href="" class="but" style="text-align: center;pointer-events: none;">...</a></div></div>
</body>
</html>

登录页面代码

<!DOCTYPE html>  
<html lang="zh_cn" xmlns:th="http://www.thymeleaf.org">
<head>  <meta charset="UTF-8">  <title>登录</title>  <link rel="stylesheet" th:href="@{/css/login.css}"><link rel="icon" th:href="@{/css/login.css}" sizes="16x16">
</head>  
<body>  <div id="login">  <h1>登录</h1>  <form th:action="@{/login}"  method="post"><input type="text" required="required" placeholder="用户名" name="username"></input><input type="password" required="required" placeholder="密码" name="password"></input><span class="remember">记住我</span><input type="checkbox" name="remember" style="width: 50px"></input><button class="but" type="submit">登录</button></form>  </div>  
</body>  
</html> 

发送邮件页面代码

<!DOCTYPE html>
<html lang="zh_cn" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><link rel="stylesheet" th:href="@{/css/sendMail.css}"><link rel="icon" th:href="@{/image/1.png}" sizes="16x16"><title>发送邮件</title>
</head>
<body><div id="mail">  <h1>发送邮件</h1>  <div ><span class="msg" th:text="${msg}"></span><a th:href="@{/index}"  class="fanhuei">返回主页</a></div><form th:action="@{/mail/snedMail}" method="post"><div><span class="text">标题:</span><input type="text" required="required" placeholder="标题" name="subject"></input></div>  <div><span class="text">内容:</span><input type="text" required="required" placeholder="内容" name="text"></input></div>  <div><span class="text">接受者邮箱:</span><input type="email" required="required" placeholder="接受者邮箱" name="to"></input></div>  <div><span class="text">发送者邮箱:</span><input type="email" required="required" placeholder="发送者邮箱" name="from"></input></div>   <button class="but" type="submit">发送</button>  </form>  </div>  
</body>
</html>

项目的制作原因

1.本人还处于后端的学习阶段虽然学了差差不多有一年多的时间了。

2.目前都是在学习SpringBoot、SpringCloud,微服务这一块的。

3.其实我一开始就是好玩的去做,也是因为在学到了在SpringBoot基础上实现邮件的发送产生了好奇。

3.就去想着结合我现在学的一些内容去整合的做一个网站但是在做的过程中去巩固关于mysql数据库的连接,使用SpringSecurity以及thymeleaf的使用

4.页面在一开始的时候也就是一个from表单这样子外加几个h1标签,目前这个页面是我在网上找的一些模板然后我去改了一下

项目总结

上面用到的核心功能在我的博客的笔记中也有,那些笔记是看狂神大佬的教学视频做的笔记

SpringSecurity配置:https://blog.csdn.net/yuran06/article/details/121561188?spm=1001.2014.3001.5501

Mybatis配置:https://blog.csdn.net/yuran06/article/details/121566373?spm=1001.2014.3001.5501

Thymeleaf配置:https://blog.csdn.net/yuran06/article/details/121566135?spm=1001.2014.3001.5501

关于邮箱的配置:https://blog.csdn.net/yuran06/article/details/121560041?spm=1001.2014.3001.5501

最后我希望我这样子因为好玩而去做了一个简单的个人邮件发送的小项目能对大家提供一些帮助,尤其是和我一样还在学习的小伙伴!!
源码地址:https://gitee.com/mehao123/sendMail/tree/master

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_883765.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[Digit Generator, ACM/ICPC Seoul 2005, UVA1583]

[Digit Generator, ACM/ICPC Seoul 2005, UVA1583] 大阻力是开10万数组的魄力… 反直觉的复杂度分析 #include <stdio.h> #include <string.h> int a[100005]; int main() {memset(a, 0, sizeof(a));for(int i1; i<100005; i) {int tmp1 i;int tmp2 i;while…

[Score, ACM/ICPC Seoul 2005, UVA1585]

[Score, ACM/ICPC Seoul 2005, UVA1585] 吐槽&#xff01;&#xff01;&#xff01; 我好心让最后一行不\n&#xff0c;结果直接wrong answer&#xff0c;全部换行结果AC… #include <stdio.h> char s[85];void showScore(char *s) {int sum 0;//int tagOfx 1;int nu…

[Molar Mass, ACM/ICPC Seoul 2007, UVA1586]

[Molar Mass, ACM/ICPC Seoul 2007, UVA1586] 主要是固定位 的思想&#xff0c;这是最后的代码&#xff0c;不过中间一直wrong answer&#xff0c;一直找不出&#xff0c;原来是15写成了14. #include <stdio.h> #include <string.h>int isnum(char c) {return c&g…

常见的网站服务器架构有哪些?

1. 初始阶段的网站架构 一般来讲&#xff0c;大型网站都是从小型网站发展而来&#xff0c;一开始的架构都比较简单&#xff0c;随着业务复杂和用户量的激增&#xff0c;才开始做很多架构上的改进。当它还是小型网站的时候&#xff0c;没有太多访客&#xff0c;一般来讲只需要一…

视频网站的几个有趣问题

目前的视频网站主要分为两类&#xff0c;一类以用户上传的内容为主(UGC网站)&#xff0c;比如YouTube、优酷、土豆&#xff1b;另一类是专业视频内容为主&#xff0c;比如Hulu、Netflix、奇艺、搜狐。 第一类网站的视频数量非常大&#xff0c;以短视频为主&#xff0c;种类丰富…

ASP.NET网站权限设计实现——套用JQuery EasyUI列表显示数据、分页、查询

分类&#xff1a; C#日记ASP.net&#xff08;vs2008平台下&#xff09;&#xff08;31&#xff09; 版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载。 有时候闲的无聊,看到extjs那么肥大,真想把自己的项目改了,最近看到一款轻型的UI感觉不错,但是在…

国内网站数量直线下降:2021年仅剩422万个

最近&#xff0c;松松编辑杰哥从站长圈了解到&#xff0c;CNNIC近期发布2021年中国网站最新数量报告&#xff0c;截至2021年6月&#xff0c;我国网站数量累计为422万个! 根据CNNIC发布的第48次《中国互联网络发展状况统计报告》报告显示杰哥得知&#xff0c;截至到今年6月&…

记录一次基于docker的网站架构方案

这个是网站的大概架构 ps&#xff1a;dc监控用于监控容器状态&#xff0c;以及查看容器运行日志&#xff0c;快速启动容器 rancher用于快速升级以及快速部署服务&#xff0c;以及做了一个高可用防止容器宕机&#xff08;容器需要写docker-compose&#xff09; zabbix用于监控…

18个配色(色彩搭配)资源网站——设计师福利

无论是在品牌视觉形象的展示&#xff0c;还是传统广告和数字营销领域的推广&#xff0c;色彩搭配实在太重要了&#xff01;然而&#xff0c;我们通常所说的&#xff1a;这个品牌真高端&#xff01;真大气&#xff01;最重要因素是由色彩搭配决定的&#xff0c;这个是给人最直接…

网站的关键!教你13步打造漂亮的WEB字体

今天&#xff0c;大多数浏览器已经默认支持Web字体&#xff0c;日趋增多的字体特性被嵌入最新版HTML和CSS标准中&#xff0c;Web字体即将迎来一个趋于复杂的崭新时代。这意味着网页设计师需要重新审视经典的字体规则——而这并非故事的结束。 印刷字体是静态的&#xff0c;而网…

大型网站架构系列:电商网站架构案例(1)

大型网站架构是一个系列文档&#xff0c;欢迎大家关注。本次分享主题&#xff1a;电商网站架构案例。从电商网站的需求&#xff0c;到单机架构&#xff0c;逐步演变为常用的&#xff0c;可供参考的分布式架构的原型。除具备功能需求外&#xff0c;还具备一定的高性能&#xff0…

大型网站架构系列:电商网站架构案例(2)

电网网站架构案例系列的第二篇文章。主要讲解网站架构分析&#xff0c;网站架构优化&#xff0c;业务拆分&#xff0c;应用集群架构&#xff0c;多级缓存&#xff0c;分布式Session。 五、网站架构分析 根据以上预估&#xff0c;有几个问题&#xff1a; 需要部署大量的服务器&…

大型网站架构系列:电商网站架构案例(3)

本文章是电商网站架构案例的第三篇&#xff0c;主要介绍数据库集群&#xff0c;读写分离&#xff0c;分库分表&#xff0c;服务化&#xff0c;消息队列的使用&#xff0c;以及本电商案例的架构总结。 6.5数据库集群&#xff08;读写分离&#xff0c;分库分表&#xff09; 大型网…

大型网站架构系列:负载均衡详解(1)

面对大量用户访问、高并发请求&#xff0c;海量数据&#xff0c;可以使用高性能的服务器、大型数据库&#xff0c;存储设备&#xff0c;高性能Web服务器&#xff0c;采用高效率的编程语言比如(Go,Scala)等&#xff0c;当单机容量达到极限时&#xff0c;我们需要考虑业务拆分和分…

大型网站架构系列:负载均衡详解(3)

本次分享大纲 软件负载均衡概述Ngnix负载均衡Lvs负载均衡Haproxy负载均衡本次分享总结 一、软件负载均衡概述 硬件负载均衡性能优越&#xff0c;功能全面&#xff0c;但是价格昂贵&#xff0c;一般适合初期或者土豪级公司长期使用。因此软件负载均衡在互联网领域大量使用。常用…

大型网站架构系列:负载均衡详解(4)

本文是负载均衡详解的第四篇&#xff0c;主要介绍了LVS的三种请求转发模式和八种负载均衡算法&#xff0c;以及Haproxy的特点和负载均衡算法。具体参考文章&#xff0c;详见最后的链接。 三、LVS负载均衡 LVS是一个开源的软件&#xff0c;由毕业于国防科技大学的章文嵩博士于19…

大型网站架构系列:分布式消息队列(一)

以下是消息队列以下的大纲&#xff0c;本文主要介绍消息队列概述&#xff0c;消息队列应用场景和消息中间件示例&#xff08;电商&#xff0c;日志系统&#xff09;。 本次分享大纲 消息队列概述消息队列应用场景消息中间件示例JMS消息服务&#xff08;见第二篇&#xff1a;大…

大型网站架构系列:消息队列(二)

本文是大型网站架构系列&#xff1a;消息队列&#xff08;二&#xff09;&#xff0c;主要分享JMS消息服务&#xff0c;常用消息中间件&#xff08;Active MQ&#xff0c;Rabbit MQ&#xff0c;Zero MQ&#xff0c;Kafka&#xff09;。【第二篇的内容大部分为网络资源的整理和汇…

12个最佳的免费学习编程的游戏网站

在这篇文章中&#xff0c;我们对 200 多个编程游戏网站的各个方面进行了评估&#xff0c;包括是否免费、是否自由开源、是面对菜鸟还是有经验的程序员、支持的编程语言等等&#xff0c;然后遴选出这 12 个上佳的免费的编程游戏网站&#xff0c;希望能让你或你的朋友(或者你的孩…

11个最值得Java开发者收藏的网站

Java是一种面向对象的编程语言&#xff0c;由Sun Microsystems公司在1995年的时候正式发布。直到今天&#xff0c;Java都一直是最受欢迎的编程语言之一。如今&#xff0c;Java应用于各种各样的技术领域&#xff0c;例如网站开发、Android开发、游戏开发、大数据等等。 在世界各…