邮件服务器MailServer之 Hibernate持久层开发

这篇博客详细介绍了如何利用Hibernate进行MailServer的数据库设计和持久层开发。首先,文章讲解了数据库的设计,包括物理模型图、表键清单和数据库脚本。接着,它指导读者在Eclipse中建立Java工程,下载Hibernate和MySQL JDBC驱动,设置Hibernate开发环境。最后,作者阐述了配置Hibernate的数据库连接、创建表映射文件,以及编写DAO层接口、实现类和测试类的过程。
摘要由CSDN通过智能技术生成

第一步:数据库设计

  • MailServer物理模型图


  • 表键的清单

名称

代码

用户昵称

nick_name

邮箱地址

mail_address

用户密码

user_password

我的邮箱

mail_address

好友邮箱

friend_address

好友备注

remark_name

邮件编号

mail_id

接收邮箱

mail_receive

发送时间

send_time

邮件主题

mail_subject

邮件正文

mail_content

发送状态

state_send

读取状态

state_read

正文编码

content_encoding

协议版本

protocol_version

定时发送

timing

邮件编号

mail_id

附件编号

adjunct_id

附件格式

adjunct_type

附件大小

adjunct_size

附件路径

adjunct_url

帐号

account

密码

password


  • 数据库脚本(先创建数据库再运行脚本)
/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50720
Source Host           : localhost:3306
Source Database       : mail_server

Target Server Type    : MYSQL
Target Server Version : 50720
File Encoding         : 65001

Date: 2018-03-31 13:39:54
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for address_book
-- ----------------------------
DROP TABLE IF EXISTS `address_book`;
CREATE TABLE `address_book` (
  `mail_address` varchar(25) NOT NULL COMMENT '我的邮件地址',
  `friend_address` varchar(25) NOT NULL COMMENT '好友邮件地址',
  `remark_name` varchar(25) DEFAULT NULL COMMENT '好友备注',
  PRIMARY KEY (`mail_address`,`friend_address`),
  CONSTRAINT `FK_Reference_1` FOREIGN KEY (`mail_address`) REFERENCES `user_entity` (`mail_address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='通讯录';

-- ----------------------------
-- Records of address_book
-- ----------------------------

-- ----------------------------
-- Table structure for adjunct
-- ----------------------------
DROP TABLE IF EXISTS `adjunct`;
CREATE TABLE `adjunct` (
  `mail_id` varchar(25) NOT NULL COMMENT '邮件ID',
  `adjunct_id` varchar(25) NOT NULL COMMENT '附件ID',
  `adjunct_type` varchar(5) DEFAULT NULL COMMENT '附件格式',
  `adjunct_size` double NOT NULL COMMENT '附件大小',
  `adjunct_url` varchar(100) NOT NULL COMMENT '附件地址',
  PRIMARY KEY (`adjunct_id`),
  KEY `FK_Reference_3` (`mail_id`),
  CONSTRAINT `FK_Reference_3` FOREIGN KEY (`mail_id`) REFERENCES `mail_entity` (`mail_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='附件表';

-- ----------------------------
-- Records of adjunct
-- ----------------------------

-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
  `account` varchar(25) NOT NULL COMMENT '管理员帐号',
  `password` varchar(25) NOT NULL COMMENT '管理员密码',
  PRIMARY KEY (`account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='管理员';

-- ----------------------------
-- Records of admin
-- ----------------------------

-- ----------------------------
-- Table structure for mail_entity
-- ----------------------------
DROP TABLE IF EXISTS `mail_entity`;
CREATE TABLE `mail_entity` (
  `mail_id` varchar(25) NOT NULL COMMENT '邮件编号',
  `mail_address` varchar(25) NOT NULL COMMENT '发送方邮箱',
  `mail_receive` varchar(25) NOT NULL COMMENT '接收方邮箱',
  `send_time` datetime NOT NULL COMMENT '发送时间',
  `mail_subject` varchar(50) NOT NULL COMMENT '邮件主题',
  `mail_content` varchar(2048) NOT NULL COMMENT '邮件正文',
  `state_send` varchar(4) NOT NULL COMMENT '发送方邮件状态',
  `state_read` varchar(2) DEFAULT NULL COMMENT '接收方邮件状态',
  `content_encoding` varchar(10) DEFAULT NULL COMMENT '邮件正文编码',
  `protocol_version` varchar(10) DEFAULT NULL COMMENT '邮件协议版本',
  `timing` datetime DEFAULT NULL COMMENT '定时发送时间',
  PRIMARY KEY (`mail_id`),
  KEY `FK_Reference_2` (`mail_address`),
  CONSTRAINT `FK_Reference_2` FOREIGN KEY (`mail_address`) REFERENCES `user_entity` (`mail_address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='邮件';

-- ----------------------------
-- Records of mail_entity
-- ----------------------------

-- ----------------------------
-- Table structure for user_entity
-- ----------------------------
DROP TABLE IF EXISTS `user_entity`;
CREATE TABLE `user_entity` (
  `nick_name` varchar(25) NOT NULL COMMENT '用户昵称',
  `mail_address` varchar(25) NOT NULL COMMENT '邮箱地址',
  `user_password` varchar(15) NOT NULL COMMENT '用户密码',
  PRIMARY KEY (`mail_address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户';

-- ----------------------------
-- Records of user_entity
-- ----------------------------
INSERT INTO `user_entity` VALUES ('佚阳', '155146872@belief', '155764
C# 开发邮件服务器 Features supports pop3 smtp imap etc. supports ssl/tls for pop3, smtp and imap. supports multi mail vitural server, can bind multi domains. supports run as windows service, winform application with or without tray icon control. supports remote management using mailservermanager.exe supports mail recycle bin supports plugins using api interfaces Build and release download source code or use the releases i provided. if from source code you should run afterbuild.bat after build the solution successfuly then you get the debug or release version from application folder. Installation run MailServerLauncher.exe to install as windows service or just run as desktop application with or without tray icon. Configuration run MailServerManager.exe at the machine runs mailserver service or app. Connect to server press connect button from menu. type server localhost or 127.0.0.1 or leave it empty type username Administrator with case sensitive type password emtpy press ok to connect with saving or not Add virtual server type name and select storage api [your vitural server]>system>general, add dns servers for query mailto's domain mx record. [your vitural server]>system>services, enable smtp and pop3 services and set ipaddress binding with or without ssl/tls. the host name is required when set bindings. eg. bind smtp service to smtp.[your.domain] + IPAddress.Any [your vitural server]>system>service>relay, 'send email using DNS' and set at least a local ipaddress binding for email sending. the name of the binding here only a name,not mean domain. [your vitural server]>system>logging, enable logging for all services when something error you can see the details from 'Logs and Events' node [your vitural server]>domains, set email host domain, eg. if your email will be xyz@abc.com then the domain should be abc.domain, description is optional [your vitural server]>security, !!! important, add rules for your service to allow outside access like email client. eg. add a rule 'Smtp Allow All' for smtp service with ip allows between 0.0.0.0 to 255.255.255.255 to enable smtp service for outside access add 'Pop3 Allow All' and 'Rlay Allow All' like that too. [your vitural server]>filters, there are two types of filter named 'DnsBlackList' and 'VirusScan' its configurable by run it's executable from mail server install path. Domain name resolution Add smtp.[your.domain], pop3.[your.domain], imap.[your.domain] resolution to your server public ip address with A record or to your server domain with CNAME record. mx record is optional if [your.domain] has a A record.if not, you shoud add a mx record point to your server ip. Remote management to enable remote management you must add ACL to allow mail server managers connect from outside network. use MailServerAccessManager.exe to add management users or just use administrator. add rules to allow access from specific IPs or ip ranges The users here only for management cases.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值