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

相关文章

C#中checked关键字的使用小结

《C#中checked关键字的使用小结》本文主要介绍了C#中checked关键字的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录✅ 为什么需要checked? 问题:整数溢出是“静默China编程”的(默认)checked的三种用

C#中预处理器指令的使用小结

《C#中预处理器指令的使用小结》本文主要介绍了C#中预处理器指令的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录 第 1 名:#if/#else/#elif/#endif✅用途:条件编译(绝对最常用!) 典型场景: 示例

Mysql中RelayLog中继日志的使用

《Mysql中RelayLog中继日志的使用》MySQLRelayLog中继日志是主从复制架构中的核心组件,负责将从主库获取的Binlog事件暂存并应用到从库,本文就来详细的介绍一下RelayLog中... 目录一、什么是 Relay Log(中继日志)二、Relay Log 的工作流程三、Relay Lo

使用Redis实现会话管理的示例代码

《使用Redis实现会话管理的示例代码》文章介绍了如何使用Redis实现会话管理,包括会话的创建、读取、更新和删除操作,通过设置会话超时时间并重置,可以确保会话在用户持续活动期间不会过期,此外,展示了... 目录1. 会话管理的基本概念2. 使用Redis实现会话管理2.1 引入依赖2.2 会话管理基本操作

Springboot请求和响应相关注解及使用场景分析

《Springboot请求和响应相关注解及使用场景分析》本文介绍了SpringBoot中用于处理HTTP请求和构建HTTP响应的常用注解,包括@RequestMapping、@RequestParam... 目录1. 请求处理注解@RequestMapping@GetMapping, @PostMappin

springboot3.x使用@NacosValue无法获取配置信息的解决过程

《springboot3.x使用@NacosValue无法获取配置信息的解决过程》在SpringBoot3.x中升级Nacos依赖后,使用@NacosValue无法动态获取配置,通过引入SpringC... 目录一、python问题描述二、解决方案总结一、问题描述springboot从2android.x

Nginx服务器部署详细代码实例

《Nginx服务器部署详细代码实例》Nginx是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务,:本文主要介绍Nginx服务器部署的相关资料,文中通过代码... 目录Nginx 服务器SSL/TLS 配置动态脚本反向代理总结Nginx 服务器Nginx是一个‌高性

SpringBoot整合AOP及使用案例实战

《SpringBoot整合AOP及使用案例实战》本文详细介绍了SpringAOP中的切入点表达式,重点讲解了execution表达式的语法和用法,通过案例实战,展示了AOP的基本使用、结合自定义注解以... 目录一、 引入依赖二、切入点表达式详解三、案例实战1. AOP基本使用2. AOP结合自定义注解3.

Python中Request的安装以及简单的使用方法图文教程

《Python中Request的安装以及简单的使用方法图文教程》python里的request库经常被用于进行网络爬虫,想要学习网络爬虫的同学必须得安装request这个第三方库,:本文主要介绍P... 目录1.Requests 安装cmd 窗口安装为pycharm安装在pycharm设置中为项目安装req

使用Python将PDF表格自动提取并写入Word文档表格

《使用Python将PDF表格自动提取并写入Word文档表格》在实际办公与数据处理场景中,PDF文件里的表格往往无法直接复制到Word中,本文将介绍如何使用Python从PDF文件中提取表格数据,并将... 目录引言1. 加载 PDF 文件并准备 Word 文档2. 提取 PDF 表格并创建 Word 表格