使用hmailserver搭建邮件服务器

2023-11-04 08:18

本文主要是介绍使用hmailserver搭建邮件服务器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

    • 安装
    • 使用outlook访问
    • 配置TLS AND SSL 支持
    • 使用java收发邮件
    • 支持IPV6
    • 查看数据文件位置
    • 常见错误
    • 附录

本文参考地址:
官方帮助文档
软件下载
各个邮件服务器软件比较
官方和自签名证书for hmailserver

安装

如果是win10 务必安装.net 3.5 参见附录
下载完软件后,开始安装:
安装所有组件
使用内嵌数据库
设置密码
连接
添加域
添加用户

使用outlook访问

在outlook里面配置连接信息:
这里写图片描述
这里需要注意的是:
1.注意这里设置的用户名必须是完整的电子邮件地址
2.这里使用的简单的本地地址.
3.如果提示找不到ISP服务器,看下是不是输错多次密码了.在hmail的配置:Settings->Advanced ->Auto-ban里面是否有拦截
4.如果还是无法找到,看下ip段是否在可登陆的地址里面.在hmail的配置:Settings->Advanced->IP Ranges
5.查看绑定的各个服务的端口在:Settings -> Advanced ->TCP/IP ports

然后就可以相互发邮件了.
这里写图片描述

配置TLS AND SSL 支持

(1)配置证书,生成证书参考:http://blog.csdn.net/scugxl/article/details/49204685
配置证书
(2)配置证书:(使用9999端口,可以自定义)
配置证书
(3)查看是否ok:
使用openssl查看是否ok
常见问题:
[1]配置后 提示启动成功,但是发现没有该端口.
netstat -ano | findstr 9999
解决办法:打开hmail的日志后查看,目前我遇到了2种情况,打开日志方式:
日志

问题1:日志中有如下错误:

“ERROR” 8768 “2015-10-17 16:00:20.920” “Severity: 2 (High), Code: HM5143, Source: TCPServer::GetPassword(), Description: The private key file has a password. hMailServer does not support this.”

解决办法:证书文件私钥文件不能有密码.
问题2:报nosuch process

“ERROR” 8396 “2015-10-17 16:57:59.496” “Severity: 2 (High), Code: HM5113, Source: SslContextInitializer::InitServer, Description: Failed to load certificate file. Path: C:\Users\gaoxi\Desktop, Address: 0.0.0.0, Port: 9999, Error: use_certificate_file: No such process”

解决办法:试试证书路径是否包含中文路径.

使用java收发邮件

Java Mail Home Page

package javamail;import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Properties;import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;import com.sun.mail.smtp.SMTPAddressFailedException;
import com.sun.mail.smtp.SMTPAddressSucceededException;
import com.sun.mail.smtp.SMTPSendFailedException;
import com.sun.mail.smtp.SMTPTransport;/*** 根据java mail examples 修改* @author gxl**/
public class smtpsend
{/*** Example of how to extend the SMTPTransport class. This example* illustrates how to issue the XACT command before the SMTPTransport issues* the DATA command.** public static class SMTPExtension extends SMTPTransport { public* SMTPExtension(Session session, URLName url) { super(session, url); // to* check that we're being used* System.out.println("SMTPExtension: constructed"); }* * protected synchronized OutputStream data() throws MessagingException { if* (supportsExtension("XACCOUNTING")) issueCommand("XACT", 250); return* super.data(); } }*/public static void main(String[] argv){String to = "user1@youdomain.com", subject = "Test subject", from = "user2@youdomain.com";String mailhost = null;String mailer = "smtpsend";String user = null, password = null;boolean debug = true;boolean verbose = false;boolean auth = false;String prot = "smtp";new BufferedReader(new InputStreamReader(System.in));try{/** Initialize the JavaMail Session.*/Properties props = System.getProperties();if (auth)props.put("mail." + prot + ".auth", "true");/** Create a Provider representing our extended SMTP transport and* set the property to use our provider.* * Provider p = new Provider(Provider.Type.TRANSPORT, prot,* "smtpsend$SMTPExtension", "JavaMail demo", "no version");* props.put("mail." + prot + ".class", "smtpsend$SMTPExtension");*/// Get a Session objectSession session = Session.getInstance(props, null);if (debug)session.setDebug(true);/** Register our extended SMTP transport.* * session.addProvider(p);*//** Construct the message and send it.*/Message msg = new MimeMessage(session);msg.setFrom(new InternetAddress(from));msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));msg.setSubject(subject);String text = "This is a test message.";// If the desired charset is known, you can use// setText(text, charset)msg.setText(text);msg.setHeader("X-Mailer", mailer);msg.setSentDate(new Date());// send the thing off/** The simple way to send a message is this:* * Transport.send(msg);* * But we're going to use some SMTP-specific features for* demonstration purposes so we need to manage the Transport object* explicitly.*/SMTPTransport t = (SMTPTransport) session.getTransport(prot);try{if (auth)t.connect(mailhost, user, password);elset.connect();t.sendMessage(msg, msg.getAllRecipients());}finally{if (verbose)System.out.println("Response: " + t.getLastServerResponse());t.close();}System.out.println("\nMail was sent successfully.");}catch (Exception e){/** Handle SMTP-specific exceptions.*/if (e instanceof SendFailedException){MessagingException sfe = (MessagingException) e;if (sfe instanceof SMTPSendFailedException){SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;System.out.println("SMTP SEND FAILED:");if (verbose)System.out.println(ssfe.toString());System.out.println("  Command: " + ssfe.getCommand());System.out.println("  RetCode: " + ssfe.getReturnCode());System.out.println("  Response: " + ssfe.getMessage());}else{if (verbose)System.out.println("Send failed: " + sfe.toString());}Exception ne;while ((ne = sfe.getNextException()) != null&& ne instanceof MessagingException){sfe = (MessagingException) ne;if (sfe instanceof SMTPAddressFailedException){SMTPAddressFailedException ssfe = (SMTPAddressFailedException) sfe;System.out.println("ADDRESS FAILED:");if (verbose)System.out.println(ssfe.toString());System.out.println("  Address: " + ssfe.getAddress());System.out.println("  Command: " + ssfe.getCommand());System.out.println("  RetCode: " + ssfe.getReturnCode());System.out.println("  Response: " + ssfe.getMessage());}else if (sfe instanceof SMTPAddressSucceededException){System.out.println("ADDRESS SUCCEEDED:");SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException) sfe;if (verbose)System.out.println(ssfe.toString());System.out.println("  Address: " + ssfe.getAddress());System.out.println("  Command: " + ssfe.getCommand());System.out.println("  RetCode: " + ssfe.getReturnCode());System.out.println("  Response: " + ssfe.getMessage());}}}else{System.out.println("Got Exception: " + e);if (verbose)e.printStackTrace();}}}}

运行输出:

Subject: Test subject
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: smtpsendThis is a test message.
.
250 Queued (0.064 seconds)
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 goodbyeMail was sent successfully.

在Outlook上看到的:
receuved email

支持IPV6

IPV6
实际配置效果如下:
[1]新增一个ipv6专用的smtp端口.
ipv6
[2]设置新增的ipv6的登陆地址段.
ipv6 range

为了方便使用,修改了下hmailServer的鉴权设置 不适用SSL.
ssl disabled

java代码:(与前面类似 只贴出了修改的点)

        String to = "user1@youdomain.com", subject = "Test subject", from = "user2@youdomain.com";boolean testipv6 = true; // 如果不测试ipv6 这里设置为false/*** test ipv6*/String smtpipv6 = "fe80::d48a:e3be:7d9d:899c";int ipv6port = 9999;String mailhost = null;
....
....SMTPTransport t = (SMTPTransport) session.getTransport(prot);try{if (auth){t.connect(mailhost, user, password);}else if (testipv6){t.connect(smtpipv6, ipv6port, "user1@youdomain.com", "123456");}else{t.connect();}t.sendMessage(msg, msg.getAllRecipients());}

查看数据文件位置

C:\Program Files (x86)\hMailServer\Bin\hMailServer.ini 地址根据你的安装路径变化.

常见错误

常见错误码参考
trouble shooting tips

附录

1.win10 安装.net 3.5
如果你是win10 需要手动启用一下.net 3.5
win10
另外的请参考:win10 下安装.net framework 3.5
ITHOME

2.本文所涉及的所有文件
百度云
Java Mail API source code or @Baidu yun

这篇关于使用hmailserver搭建邮件服务器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/344438

相关文章

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

prometheus如何使用pushgateway监控网路丢包

《prometheus如何使用pushgateway监控网路丢包》:本文主要介绍prometheus如何使用pushgateway监控网路丢包问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录监控网路丢包脚本数据图表总结监控网路丢包脚本[root@gtcq-gt-monitor-prome

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

SpringBoot中如何使用Assert进行断言校验

《SpringBoot中如何使用Assert进行断言校验》Java提供了内置的assert机制,而Spring框架也提供了更强大的Assert工具类来帮助开发者进行参数校验和状态检查,下... 目录前言一、Java 原生assert简介1.1 使用方式1.2 示例代码1.3 优缺点分析二、Spring Fr

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

SpringBoot线程池配置使用示例详解

《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

C++ Log4cpp跨平台日志库的使用小结

《C++Log4cpp跨平台日志库的使用小结》Log4cpp是c++类库,本文详细介绍了C++日志库log4cpp的使用方法,及设置日志输出格式和优先级,具有一定的参考价值,感兴趣的可以了解一下... 目录一、介绍1. log4cpp的日志方式2.设置日志输出的格式3. 设置日志的输出优先级二、Window