我发现在 Windows 中创建邮件服务器的最简单方法是安装 Python,然后使用内置的 SMTP 调试服务器和以下单行:
python -m smtpd -c DebuggingServer -n localhost:25
在 Windows 上,我发现它有时对 localhost 和 127.0.0.1 有奇怪的行为,因此,如果一切都失败了,您可以尝试使用“ipconfig”命令(在 DOS 命令提示符下)查找您的 IP 地址,然后您可能会看到类似:
c:\> ipconfig
-- stuff cut here ---
Wireless LAN adapter WiFi:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::856d:fd33:3e01:e656%9
IPv4 Address. . . . . . . . . . . : 192.168.8.111
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.8.1
并且,假设你发现你的 IP 地址是 192.168.8.11(就像我在上面的例子中所做的那样),然后将命令更改为:
python -m smtpd -c DebuggingServer -n 192.168.8.11:25
并在您的 php.ini 文件中设置以下行:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = 192.168.8.111
; http://php.net/smtp-port
smtp_port = 25
而且,这在我没有其他方法的情况下对我有用!
我还注意到您可以通过输入以下命令来检查您的本地邮件服务器是否正常工作:
C:/> telnet localhost 25
或者对于我的第二个配置:
C:/> telnet 192.168.8.111 25
Telnet 在 Linux 上是免费的,但要在 Windows 上使用它,您必须转到“程序和功能”,然后单击“打开和关闭 Windows 功能”(从左侧的小面板中),然后选中该框Windows 功能列表中的“Telnet 客户端”。
当你运行 telnet 命令时,如果服务器没有运行,你会看到类似这样的信息:
C:\Projects>telnet localhost 25
Connecting To localhost...Could not open connection to the host, on port 25: Connect failed
但是,如果一切正常,您应该清除屏幕并从邮件服务器返回“服务器标识符”字符串。在我的机器上看起来像这样:
220 ZOOT Python SMTP proxy version 0.3
如果您真的很热衷,您可以输入一些 SMTP 命令并在此处发送邮件,或者您可以输入“退出”以断开与服务器的连接。