使用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

相关文章

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

MySQL 中的服务器配置和状态详解(MySQL Server Configuration and Status)

《MySQL中的服务器配置和状态详解(MySQLServerConfigurationandStatus)》MySQL服务器配置和状态设置包括服务器选项、系统变量和状态变量三个方面,可以通过... 目录mysql 之服务器配置和状态1 MySQL 架构和性能优化1.1 服务器配置和状态1.1.1 服务器选项

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

Java中String字符串使用避坑指南

《Java中String字符串使用避坑指南》Java中的String字符串是我们日常编程中用得最多的类之一,看似简单的String使用,却隐藏着不少“坑”,如果不注意,可能会导致性能问题、意外的错误容... 目录8个避坑点如下:1. 字符串的不可变性:每次修改都创建新对象2. 使用 == 比较字符串,陷阱满

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定