linux shell 傳送email 郵件

2021-08-21 12:25:37 字數 2243 閱讀 7502

方法一:簡單郵件傳送

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

效果截圖

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

# !/bin/shfrom_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格式傳送郵件

# !/bin/shfrom='[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

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

android Intent傳送文字email

如下 import android.content.intent import android.os.bundle import android.view.view import android.view.view.onclicklistener import android.widget.butt...

使用python傳送html格式的email

和大夥分享乙個使用python傳送html格式的email的 我用在我的軟體的bug提交中。如下。請將 中的email和密碼替換成您的email和密碼。coding cp936 send email via gmail,support html email by jibo he hejibo ues...

linux shell 傳送郵件

vim etc mail.rc 檔案尾增加以下內容 set from 1968089885 qq.com smtp smtp.qq.com set smtp auth user 1968089885 qq.com smtp auth password 123456 set smtp auth log...