linux用shell發郵件

2021-07-11 05:13:39 字數 2311 閱讀 5408

方法一:簡單郵件傳送

echo 'hello world' | mail -s "subject" -t  [email protected],[email protected]    -a from:[email protected]

效果截圖

方法二: 文字格式傳送郵件

[python]view plain

copy

print

?# !/bin/sh

from_name="from@yanggang"

from

="[email protected]"

to="[email protected]"

email_title="test mail"

email_content="/home/barry/top800/test/output_email.html"

email_subject="top800_games_free_usa"

echo -e "to: \"$\" \nfrom: \"$\" \nsubject: $\n\n`cat $`"

| /usr/sbin/sendmail -t  

效果截圖:

方法三:html格式傳送郵件

[python]view plain

copy

print

?# !/bin/sh

from

='[email protected]'

to='[email protected]'

email_date=''

email_content='/home/barry/top800/test/output_email.html'

email_subject='top800_game_free_usa'

function send_email()  

send_email  

效果截圖:

--------------------------------

centos是乙個非常不錯的免費開源linux系統,許多站點首選的平台。

然而centos預設不能傳送郵件,需要傳送郵件的童鞋可以安裝乙個sendmail程式。

安裝sendmail

執行: [root@vps478753 ~]# yum -y install sendmail

程式會自動搜尋出sendmail安裝程式自動安裝,安裝好sendmail以後執行以下命令啟動sendmail

[root@vps478753 ~]#

/etc/init.d/sendmail start

starting sendmail:                                         [  ok  ]

starting sm-client:                                        [  ok  ]

啟動以後我們可以執行mail命令測試一下是否能傳送郵件

一、通過檔案內容傳送郵件

[root@vps478753 ~]# mail -s 'test mail' [email protected] < /etc/passwd

很快收到郵件了,正文是 /etc/passwd 檔案的內容

二、使用管道符直接傳送郵件內容

如果不想通過檔案傳送郵件內容也可以這麼傳送

[root@vps478753 ~]# echo "this is test mail" | mail -s 'test mail' [email protected]

以上效果同檔案傳送郵件內容一樣

如果提示mail: command not found

[root@vps478753 ~]# mail -s 'test mail' 

[email protected] < /etc/passwd

-bash: mail: command not found

那麼就是沒有安裝mail命令,此時需要安裝mail命令

[root@vps478753 ~]# yum install mailx -y

然後再重新傳送以下郵件就好了!

用CDONTS NewMail發郵件

last updated by recon on 05 14 2001 on error resume next 利用cdonts元件在win2k上傳送郵件 dim objmail 普通郵件 無主體 set objmail server.createobject cdonts.newmail obj...

用Delphi發郵件

用delphi發郵件 控制項idsmtp1 tidsmtp idmessage1 tidmessage idsmtp1.host smtp.163.com idsmtp1.port 25 idsmtp1.username 發信人名稱 idsmtp1.password 發信人郵箱密碼 idsmtp1....

用python發郵件

python內建對smtp支援,可傳送純文字,html以及帶附件的郵件以下是傳送純文字郵件的 把email模組和smtplib模組引入進來,使用mimetext構造了郵件內容 from email import encoders from email.mime.text import mimetex...