mailx 或telnet 使用指定SMTP伺服器傳送郵件

gxlineji發表於2016-09-08

一、Mailx 使用指定SMTP伺服器傳送郵件的配置

redhat 伺服器上,mailx 使用指定SMTP伺服器傳送郵件的配置。
在 /etc/mail.rc  最後增加如下SMTP配置:

set from=xxx@gmail.com
set smtp=smtp.gmail.com
set smtp-auth-user=xxx@gmail.com
set smtp-auth-password=yourpassword
set smtp-auth=login

(1)filename.txt內容有郵件正文
mailx -s "bo pv alert" xxx@gmail.com  <  filename.txt

(2)帶附件vfile.txt的郵件
echo -e "mail context.\n 請另存為為cvs檔案,然後用excel開啟,否則會顯示亂碼.\n 如有問題,請聯絡xxx.\n this mail comes from host"|mailx -s "mail subject" -a vfilename.txt -c xxx@162.com yyy@163.com

另外,mutt傳送郵件
帶附件的郵件:
echo "`cat $v_filename2`" |/usr/bin/mutt -e "my_hdr from:" -s "Report subject"  -a $v_filename1  $v_mail_rec  -c  $v_mail_cc

二、手工使用telnet發生郵件

telnet mail.xxx.com 25 
EHLO mail.xxx.com
AUTH LOGIN
aXRtb25pdG9y  #select UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw('yourusername'))) from dual;
RjMxSFo3YnFlRA== #select UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw('yourpassword'))) from dual;
MAIL FROM:
RCPT TO:
DATA
From:it@xxx.com
To:your-mail@xxx.com
Subject:test mail
Content-Type: text/plain; Charset=GB2312 
Hi, test2 
This is a test mail, you don't reply it.
.
quit

三、shell 使用telnet發生郵件

shell 自動傳送:
mail.sh 

點選(此處)摺疊或開啟

  1. #!/bin/sh
  2. # mail.sh
  3. msg="This is a test mail, you don't reply it."
  4. {
  5. sleep 1
  6. echo "EHLO mail.xxx.com"
  7. sleep 1
  8. echo "AUTH LOGIN"
  9. sleep 1
  10. echo "aXRtb25pdG9y"
  11. sleep 1
  12. echo "RjMxSFo3YnFlRA=="
  13. sleep 1
  14. echo 'MAIL FROM:'
  15. echo 'RCPT TO:'
  16. echo 'RCPT TO:'
  17. echo "DATA"
  18. sleep 1
  19. echo 'From:it@xxx.com'
  20. echo 'To:your-mail@xxx.com,your-mail@xxx.com'
  21. echo 'Subject:test mail'
  22. echo 'Content-Type: text/plain; Charset=GB2312 '
  23. echo
  24. echo
  25. echo "Hi, test2 "
  26. echo $msg
  27. echo
  28. echo
  29. echo '.'
  30. echo 'quit'
  31. } | telnet mail.xxx.com 25




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10995764/viewspace-2124727/,如需轉載,請註明出處,否則將追究法律責任。

相關文章