发送邮件

Holamail 是一个轻量级 SMTP listener。它接受基础命令 HELO/EHLOMAIL FROMRCPT TODATAQUIT,然后记录消息。它不会向外部收件人投递邮件。

连接信息

参数 公共测试主机 本地实例
Host smtp.testmail.hola.cloud localhost
Port 25 2525
Encryption None None
Authentication None None

Holamail 不支持 STARTTLS 或 SMTP AUTH。

SMTP 流程

1HELO client.example.com
2MAIL FROM:<noreply@example.com>
3RCPT TO:<user@example.com>
4DATA
5Subject: Hello from Holamail
6
7This message will be logged by Holamail.
8.
9QUIT

示例

使用 curl

curl --url smtp://smtp.testmail.hola.cloud:25 \
     --mail-from noreply@example.com \
     --mail-rcpt user@example.com \
     --upload-file email.txt
GET / HTTP/1.1
Host: smtp.testmail.hola.cloud:25
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("GET", "smtp://smtp.testmail.hola.cloud:25", nil)
	if err != nil {
		panic(err)
	}

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'smtp://smtp.testmail.hola.cloud:25',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

response = requests.request(
    "GET",
    "smtp://smtp.testmail.hola.cloud:25"
)

print(response.text)
const response = await fetch("smtp://smtp.testmail.hola.cloud:25", {
  method: "GET"
});

console.log(await response.text());
const response = await fetch("smtp://smtp.testmail.hola.cloud:25", {
  method: "GET"
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("smtp://smtp.testmail.hola.cloud:25"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

email.txt 内容:

1Subject: Hello from Holamail
2
3This message will be logged by Holamail.

明文 TCP 会话

1telnet localhost 2525

然后输入:

1HELO client.example.com
2MAIL FROM:<noreply@example.com>
3RCPT TO:<user@example.com>
4DATA
5Subject: Local Holamail test
6
7Hello from a local Holamail listener.
8.
9QUIT

预期行为

Holamail 接受语法有效的 SMTP 输入并记录消息。它适合验证应用能否使用 SMTP,而不会发送真实邮件。

不支持外部投递、HTTP API、STARTTLS、AUTH、限速、模板、分析或追踪。

评论

发表评论