下command 使用gmail來寄信

-----自己實測OK-----

使用gmail 來寄信,夾兩個檔,寄給兩個不同domain的人,中文主旨
swaks --from admin@CCC.com --to knick@AAA.com,knick@BBB.com --auth --auth-user=XXXXXX --auth-password=XXXXXX -tls --server smtp.gmail.com:587 --header "Subject:test 中文" --attach text.pdf --attach photo.jpg

mutt -s 阿貓測試信 -a cats_1.jpg -- knick@mos.com.tw

------原文內容------------

行 swaks 快速測試 SMTP


如何用 telnet 來測試 SMTP 已是基本常識了,但 swaks 這工具可以更省力些

如何測試SMTP?
telnet 的指令很單純,網路上也很多的教學,但最早怎麼測 SMTP 的文件,應該是這篇 RFC 821 ,說明了telnet之後下什麼指令測試透過swaks把這些常重覆會用到的語法包裝成下參數的方式來執行。

簡易安裝
swaks 已在Linux裡有現成的套件

但觀察這套件其實就是只有一個 perl script

快速使用
若沒有指定 from 的話,會用 linux 本身的帳號及主機名稱為 from 來寄測試信:
  1. $ swaks --to root@othercompany.com --server mycompany.com
  2. === Trying mycompany.com:25...
  3. === Connected to mycompany.com.
  4. <- 220 mycompany.com ESMTP Postfix
  5. -> EHLO AP
  6. <- 250-mycompany.com
  7. <- 250-PIPELINING
  8. <- 250-SIZE 10240000
  9. <- 250-VRFY
  10. <- 250-ETRN
  11. <- 250-ENHANCEDSTATUSCODES
  12. <- 250-8BITMIME
  13. <- 250 DSN
  14. -> MAIL FROM:
  15. <- 250 2.1.0 Ok
  16. -> RCPT TO:
  17. <** 454 4.7.1 : Relay access denied
  18. -> QUIT
  19. <- 221 2.0.0 Bye
  20. === Connection closed with remote host.
$ swaks --to root@othercompany.com --server mycompany.com
=== Trying mycompany.com:25...
=== Connected to mycompany.com.
<-  220 mycompany.com ESMTP Postfix
 -> EHLO AP
<-  250-mycompany.com
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250 DSN
 -> MAIL FROM:
<-  250 2.1.0 Ok
 -> RCPT TO:
<** 454 4.7.1 : Relay access denied
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

指定 --from 能指定寄件者名稱,
  1. $ swaks --from singernew@mycompany.com --to root@othercompany.com --helo=unqualified --server othercompany.com
  2. === Trying othercompany.com:25...
  3. === Connected to othercompany.com.
  4. <- 220 othercompany.com ESMTP Postfix
  5. -> EHLO unqualified
  6. <- 250-othercompany.com
  7. <- 250-PIPELINING
  8. <- 250-SIZE 10240000
  9. <- 250-VRFY
  10. <- 250-ETRN
  11. <- 250-ENHANCEDSTATUSCODES
  12. <- 250-8BITMIME
  13. <- 250 DSN
  14. -> MAIL FROM:
  15. <- 250 2.1.0 Ok
  16. -> RCPT TO:
  17. <- 250 2.1.5 Ok
  18. -> DATA
  19. <- 354 End data with .
  20. -> Date: Sat, 12 Oct 2013 07:34:49 +0800
  21. -> To: root@othercompany.com
  22. -> From: singernew@mycompany.com
  23. -> Subject: test Sat, 12 Oct 2013 07:34:49 +0800
  24. -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
  25. ->
  26. -> This is a test mailing
  27. ->
  28. -> .
  29. <- 250 2.0.0 Ok: queued as 964DB49A53
  30. -> QUIT
  31. <- 221 2.0.0 Bye
  32. === Connection closed with remote host.
$ swaks --from singernew@mycompany.com --to root@othercompany.com --helo=unqualified --server othercompany.com
=== Trying othercompany.com:25...
=== Connected to othercompany.com.
<-  220 othercompany.com ESMTP Postfix
 -> EHLO unqualified
<-  250-othercompany.com
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250 DSN
 -> MAIL FROM:
<-  250 2.1.0 Ok
 -> RCPT TO:
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with .
 -> Date: Sat, 12 Oct 2013 07:34:49 +0800
 -> To: root@othercompany.com
 -> From: singernew@mycompany.com
 -> Subject: test Sat, 12 Oct 2013 07:34:49 +0800
 -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 ->
 -> This is a test mailing
 ->
 -> .
<-  250 2.0.0 Ok: queued as 964DB49A53
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

若把 --server 的參數拿掉,則會自動找收件者的 MX 記錄,再往該 MX 去測試:
  1. $ swaks --from singernew@mycompany --to root@othercompany.com --helo=unqualified
  2. === Trying nopam.othercompany.com:25...
  3. === Connected to nopam.othercompany.com.
  4. <- 220 nopam.othercompany.com SW-Nopam+ ****
  5. -> EHLO unqualified
  6. <- 250-nopam.othercompany.com
  7. <- 250-PIPELINING
  8. <- 250-SIZE 209915200
$ swaks --from singernew@mycompany --to root@othercompany.com --helo=unqualified
=== Trying nopam.othercompany.com:25...
=== Connected to nopam.othercompany.com.
<-  220 nopam.othercompany.com SW-Nopam+ ****
 -> EHLO unqualified
<-  250-nopam.othercompany.com
<-  250-PIPELINING
<-  250-SIZE 209915200
...

指定內容
測試的信件內容預設為 This is a test mailing,若要指定內容可以用這語法指到文字檔:
  1. --body /path/to/gtube/file
--body /path/to/gtube/file

若要測試寄病毒信件會有什麼結果,可用這樣子的指令:
  1. swaks -t user@example.com --attach - --server test-server.example.com --suppress-data
swaks -t user@example.com --attach - --server test-server.example.com --suppress-data 
網管就是希望能用最省力的工具來做測試

參考資料:
swaks 官網
swaks - Swiss Army Knife SMTP, the all-purpose smtp transaction tester
Testing SMTP servers with SWAKS