Related Posts Plugin for WordPress, Blogger...

2013年11月21日

下command 使用gmail來寄信

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

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

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

行 swaks 快速測試 SMTP


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

簡易安裝
swaks 已在Linux裡有現成的套件
  1. # pacman -S swaks  
  2. resolving dependencies...  
  3. looking for inter-conflicts...  
  4. Packages (3): perl-net-dns-0.72-2  perl-net-ip-1.26-1  swaks-20130209.0-1  
  5. Total Download Size:    0.34 MiB  
  6. Total Installed Size:   0.91 MiB  
  7. :: Proceed with installation? [Y/n]  
  8. :: Retrieving packages ...  
  9.  perl-net-ip-1.26-1-any              24.4 KiB  4.77M/s 00:00 [################################] 100%  
  10.  perl-net-dns-0.72-2-x86_64         262.8 KiB  7.55M/s 00:00 [################################] 100%  
  11.  swaks-20130209.0-1-any              59.4 KiB  11.6M/s 00:00 [################################] 100%  
  12. (3/3) checking keys in keyring                               [################################] 100%  
  13. (3/3) checking package integrity                             [################################] 100%  
  14. (3/3) loading package files                                  [################################] 100%  
  15. (3/3) checking for file conflicts                            [################################] 100%  
  16. (3/3) checking available disk space                          [################################] 100%  
  17. (1/3) installing perl-net-ip                                 [################################] 100%  
  18. (2/3) installing perl-net-dns                                [################################] 100%  
  19. (3/3) installing swaks                                       [################################] 100%  
# pacman -S swaks  resolving dependencies...  looking for inter-conflicts...    Packages (3): perl-net-dns-0.72-2  perl-net-ip-1.26-1  swaks-20130209.0-1    Total Download Size:    0.34 MiB  Total Installed Size:   0.91 MiB    :: Proceed with installation? [Y/n]  :: Retrieving packages ...   perl-net-ip-1.26-1-any              24.4 KiB  4.77M/s 00:00 [################################] 100%   perl-net-dns-0.72-2-x86_64         262.8 KiB  7.55M/s 00:00 [################################] 100%   swaks-20130209.0-1-any              59.4 KiB  11.6M/s 00:00 [################################] 100%  (3/3) checking keys in keyring                               [################################] 100%  (3/3) checking package integrity                             [################################] 100%  (3/3) loading package files                                  [################################] 100%  (3/3) checking for file conflicts                            [################################] 100%  (3/3) checking available disk space                          [################################] 100%  (1/3) installing perl-net-ip                                 [################################] 100%  (2/3) installing perl-net-dns                                [################################] 100%  (3/3) installing swaks                                       [################################] 100%

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

快速使用
若沒有指定 from 的話,會用 linux 本身的帳號及主機名稱為 from 來寄測試信:
  1. $ swaks --to [email protected] --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:<singernew@ithelp>  
  15. <-  250 2.1.0 Ok  
  16.  -> RCPT TO:<[email protected]>  
  17. <** 454 4.7.1 <[email protected]>: Relay access denied  
  18.  -> QUIT  
  19. <-  221 2.0.0 Bye  
  20. === Connection closed with remote host.  
$ swaks --to [email protected] --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:<singernew@ithelp>  <-  250 2.1.0 Ok   -> RCPT TO:<[email protected]>  <** 454 4.7.1 <[email protected]>: Relay access denied   -> QUIT  <-  221 2.0.0 Bye  === Connection closed with remote host.

指定 --from 能指定寄件者名稱,
  1. $ swaks --from [email protected] --to [email protected] --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:<[email protected]>  
  15. <-  250 2.1.0 Ok  
  16.  -> RCPT TO:<[email protected]>  
  17. <-  250 2.1.5 Ok  
  18.  -> DATA  
  19. <-  354 End data with <CR><LF>.<CR><LF>  
  20.  -> Date: Sat, 12 Oct 2013 07:34:49 +0800  
  21.  -> To: [email protected]  
  22.  -> From: [email protected]  
  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 [email protected] --to [email protected] --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:<[email protected]>  <-  250 2.1.0 Ok   -> RCPT TO:<[email protected]>  <-  250 2.1.5 Ok   -> DATA  <-  354 End data with <CR><LF>.<CR><LF>   -> Date: Sat, 12 Oct 2013 07:34:49 +0800   -> To: [email protected]   -> From: [email protected]   -> 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 [email protected] --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 [email protected] --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 [email protected] --attach - --server test-server.example.com --suppress-data </path/to/eicar.txt  
swaks -t [email protected] --attach - --server test-server.example.com --suppress-data </path/to/eicar.txt

網管就是希望能用最省力的工具來做測試

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

從 Evernote 傳送記事
Categories: ,

0 意見: