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

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

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

优化的地方

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

效果

登录前的主界面

在这里插入图片描述

登录界面

在这里插入图片描述

登录后的主界面

在这里插入图片描述

发送邮箱界面

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

项目的概述

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

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

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

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

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

核心功能代码

后端

数据库的连接

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/meweb?serverTimezone=UTC&userUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource

#下面这一块是一些Durid的设置不设置也是可以的
    #Spring Boot 默认是不注入这些属性值的,需要自己绑定
    #druid 数据源专有配置
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    #配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入
    #如果允许时报错  java.lang.ClassNotFoundException: org.apache.log4j.Priority
    #则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4j
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: 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 {

    @Autowired
    JavaMailSenderImpl mailSender;

    @Async
    public 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 mapper
        PUBLIC "-//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 {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfo getUserInfo(String username) {
        return userInfoMapper.getUserInfo(username);
    }
}

SpringSecurity这块的功能代码

创建一个类去实现UserDetailsService接口

@Component
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private UserInfoService userInfoService;

    @Override
    public 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 {
    @Autowired
    private CustomUserDetailsService customUserDetailsService;

    @Override
    protected 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();					// 禁用csrf
        http.logout().logoutSuccessUrl("/");	// 设置当注销用户时跳转的页面
        http.rememberMe().rememberMeParameter("remeber");	// 设置当前用户是否记住我默认保留14天
    }

    @Override
    protected 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

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
基于SpringBoot+Vue的商务安全邮箱邮件收发是一个集成了前端和后端技术的邮箱收发邮件平台,主要用于商务邮件的接收和发送,保证商务信息的安全性和准确性。该系统的源码、部署说明和系统介绍已经打包成一个zip文件,方便用户使用。 该系统的前端部分采用了Vue框架进行开发,主要实现了用户界面和交互,包括登录、注册、邮件接收、邮件发送等功能。而后端部分则采用了SpringBoot框架,负责处理用户请求、管理用户数据并提供相应的API接口。 该系统可以方便地接收和发送商务邮件,支持邮件的加密、签名、附件等功能,确保商务信息的安全性和准确性。用户可以方便地接收和发送邮件,附件等信息。同时,该系统还支持对用户权限的管理,可以对不同用户进行分组和授权,确保信息的安全性。 对于商务人员而言,该系统可以保证商务信息的安全性和准确性,方便快捷地管理和发送商务邮件。同时,对于开发者而言也是一个学习Vue和SpringBoot技术的不错案例,值得一试。 总之,基于SpringBoot+Vue的商务安全邮箱邮件收发系统是一个功能齐全、易用、实用性很高的邮箱收发平台,能够保证商务信息的准确性和安全性,提高了商务邮件发送和接收的效率。同时,对于开发者而言也是一个学习Vue和SpringBoot技术的不错案例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是鱼染哟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值