直接連線到Mail Server,用Command來寄發Mail

 有時候會遇到使用者收不到程式自動寄發信件的問題,可以用Command的方式來測試Mail Server,記錄一下步驟:

用Telnet登入Mail Server,假設Mail server的IP是192.168.1.100,Port是25
$ telnet 192.168.1.100 25

成功登入Mail Server後,首先用helo或ehlo跟Server打招呼,成功會回傳250的Code
HELO

輸入指令MAIL FROM:<email address>,讓mail server知道是誰要寄信,如果mail server允許寄件人則會回傳成功的Code:250
MAIL FROM: test01@test.com

輸入指令RCPT TO:<email address>,收件人,成功會回傳250的Code
RCPT TO: test02@test.com

接著輸入指令DATA,通知Server要準備要輸入信件的主旨與內容
DATA

輸入指令SUBJECT: <text>,主旨,按下Enter
SUBJECT: test subject

接著開始輸入內容,預設在新行頭一字輸入「.」來可以結束內容,就可以把信寄發出去

要結束Telnet,輸入quit就可以離開了。


下面是實際的例子:

[2023-12-06 10:29.25]  ~

[test.6138] ➤ telnet 192.168.1.100 25

Trying 192.168.1.100...

Connected to 192.168.1.100.

Escape character is '^]'.

220 test-mail.server.local Microsoft ESMTP MAIL Service ready at Wed, 6 Dec 2023 10:30:09 +0800

HELO

250 test-mail.server.local Hello [192.168.1.39]

MAIL FROM: test01@test.com

250 2.1.0 Sender OK

RCPT TO: test02@test.com

250 2.1.5 Recipient OK

DATA

354 Start mail input; end with <CRLF>.<CRLF>

SUBJECT: test subject


body test

.

250 2.6.0 <8cd94457@test-mail.server.local> Queued mail for delivery