AgentSkillsCN

send-mail

在发送测试邮件并追踪其通过邮件基础设施的投递过程时使用。可触发的指令包括测试邮件流程、调试邮件路由、验证邮件追踪工具是否正常运行,或当用户说“发送邮件并追踪”时使用。

SKILL.md
--- frontmatter
name: send-mail
description: use when sending test emails and tracing their delivery through the mail infrastructure. triggers include testing mail flows, debugging mail routing, verifying mailtrace tools work, or when user says send mail and trace.
allowed-tools: Bash, Read

Send Mail and Trace

Send test emails through the mail infrastructure and trace their complete delivery path.

Prerequisites

  • mailtrace MCP server running with valid config
  • Network access: Client IP must be authorized by mail server relay policy, OR valid SMTP credentials in data-generator/.env

Workflow

dot
digraph send_mail_trace {
    rankdir=TB;

    "Send email with unique subject" [shape=box];
    "Sending failed?" [shape=diamond];
    "Wait 10-30 seconds" [shape=box];
    "Query logs by recipient email" [shape=box];
    "Found mail IDs?" [shape=diamond];
    "Trace mail by ID" [shape=box];
    "Report delivery status" [shape=box];
    "Extend time range and retry" [shape=box];
    "Trace existing mail instead" [shape=box];

    "Send email with unique subject" -> "Sending failed?";
    "Sending failed?" -> "Trace existing mail instead" [label="yes - access denied"];
    "Sending failed?" -> "Wait 10-30 seconds" [label="no"];
    "Wait 10-30 seconds" -> "Query logs by recipient email";
    "Trace existing mail instead" -> "Query logs by recipient email";
    "Query logs by recipient email" -> "Found mail IDs?";
    "Found mail IDs?" -> "Trace mail by ID" [label="yes"];
    "Found mail IDs?" -> "Extend time range and retry" [label="no"];
    "Extend time range and retry" -> "Query logs by recipient email";
    "Trace mail by ID" -> "Report delivery status";
}

Step 1: Send Test Email

Use the wrapper script in this skill directory:

bash
/home/efficacy38/.claude/skills/send-mail/scripts/send-mail \
    --config config.yaml \
    --ssl-mode starttls \
    --no-ssl-verify \
    --rate 1 \
    --duration 1 \
    --mail-subject "Test $(date +%Y-%m-%d_%H:%M:%S) - Mailtrace Verification" \
    --export-records /tmp/sent_emails.json

The wrapper script automatically:

  • Changes to the data-generator directory
  • Loads credentials from .env
  • Runs the traffic generator via uvx

SSL Mode Options

ModePortDescriptionCommand
none25No encryption (plain SMTP)--ssl-mode none
starttls587/25Upgrade to TLS after connecting--ssl-mode starttls
smtps465SSL/TLS from connection start--ssl-mode smtps --server-port 465

Common Flags

FlagPurpose
--ssl-mode <mode>SSL/TLS mode (none, starttls, smtps)
--no-ssl-verifySkip SSL certificate verification (for self-signed certs)
--rate 1 --duration 1Send single email
--mail-subjectInclude timestamp for traceability
--export-recordsSave email metadata (message-id, queue-id) for tracing
--no-authDisable authentication
--server-host <host>Override SMTP server from config
--server-port <port>Override SMTP port

Exported records format (/tmp/sent_emails.json):

json
[
  {
    "timestamp": "2026-01-27T15:00:00.123456+00:00",
    "message_id": "<uuid@traffic-generator.local>",
    "queue_id": "ABC123DEF",
    "subject": "Test 2026-01-27_15:00:00 - Mailtrace Verification",
    "from": "sender@example.com",
    "to": "recipient@example.com",
    "success": true,
    "status_code": 250
  }
]

Use queue_id from this file to directly trace with mailtrace_trace_mail.

Step 2: Wait for Delivery

bash
sleep 15

Mail typically takes 5-30 seconds to traverse relay chain.

Step 3: Query Logs

Use mailtrace MCP tool with email address or domain (not status phrases):

code
mailtrace_query_logs(
    host="csmail1.test.cc.cs.nctu.edu.tw",
    keywords=["recipient@domain.com"],
    time="2026-01-27 15:00:00",  # current time, server timezone (+08:00)
    time_range="1h"
)

Valid keywords: Email addresses (user@example.com), domains (example.com)

Invalid keywords: Status phrases like status=sent won't match - these are log field values, not searchable text.

Step 4: Trace Mail

Use returned mail_id to trace complete path:

code
mailtrace_trace_mail(
    host="csmail1.test.cc.cs.nctu.edu.tw",
    mail_id="ABC123DEF",
    time="2026-01-27 15:00:00",
    time_range="1h"
)

Step 5: Verify Delivery

Check trace results for:

  • status=sent with dsn=2.0.0 = successful delivery
  • status=deferred = temporary failure, will retry
  • status=bounced = permanent failure

Quick Reference

TaskCommand/Tool
Send email (STARTTLS)send-mail --config config.yaml --ssl-mode starttls --no-ssl-verify --rate 1 --duration 1
Send to different hostsend-mail --config config.yaml --server-host <hostname> ...
Query logsmailtrace_query_logs with recipient email
Trace pathmailtrace_trace_mail with mail_id
Check configdata-generator/config.yaml for SMTP settings
Credentialsdata-generator/.env (username/password)

Troubleshooting

ErrorSolution
530 5.7.0 Must issue STARTTLSUse --ssl-mode starttls
SSL: WRONG_VERSION_NUMBERPort/mode mismatch: use starttls for port 25/587, smtps for port 465
SSL: CERTIFICATE_VERIFY_FAILEDAdd --no-ssl-verify for self-signed certificates
554 5.7.1 Client host rejectedCheck .env credentials or network access
554 no valid recipientsServer requires auth - ensure .env has credentials
535 Authentication failedCheck credentials in .env or use --no-auth to skip auth
No mail IDs foundExtend time_range to 2h or check keyword spelling
Empty trace graphMail delivered locally without relay hops

Mail Server Clusters

  • smtp-cluster: csmail1, csmail2 (outgoing relay) - start here for sent mail
  • mx-cluster: csmx1, csmx2 (incoming mail)
  • mailer-cluster: mailer4 (application mail)
  • maillist-cluster: maillist1, maillist2 (mailing lists)