前言
linux 系統中常見的郵件發送服務有sendmai 和sendEmail 兩個是完全不同的東西
(1)sendmail
簡介
Linux服務器mail程序本身就是調用sendmail來進行郵件發送的,sendmail服務器提供對外的郵件發送功能。CentOS默認不能發送郵件,需要發送郵件的童鞋可以安裝一個sendmail程序
安裝
[root@ProxyServer ~]
# yum -y install sendmail
[root@ProxyServer ~]
# /etc/init.d/sendmail start
[root@ProxyServer ~]
# chkconfig sendmail on
[root@ProxyServer ~]
# man mail
使用
1、通過命令行發送郵件
第一行是輸入的命令,-s表示郵件的主題,後面的justin@51cto.com則是郵件的接收人,輸入完這行命令後回車,會進入郵件正文的編寫,可以輸入任何文字,比如上面的三行。當郵件正文輸入完成後,需要按CTRL+D結束輸入,此時會提示你輸入Cc地址,即郵件抄送地址,沒有直接回車就完成了郵件的發送。
2、使用管道進行郵件發送
echo "hello,echo"|mail -s "echo" [email protected]
3、使用文件進行郵件發送
mail -s "password" [email protected] < /etc/passwd
4、使用外部smtp(qq的SMTP)來發送郵件
bin/mail會默認使用本地sendmail發送郵件,這樣要求本地的機器必須安裝和啓動Sendmail服務,而通過修改配置文件/etc/mail.rc(/etc/nail.rc)可以使用外部SMTP服務器,可以達到不使用sendmail而用外部的smtp服務器發送郵件的目的。
[root@ProxyServer ~] # vim /etc/mail.rc #文末添加以下 [root@ProxyServer ~] # source /etc/mail.rc [root@ProxyServer ~] # mail -s "51cto" 15001*****@139.com < /etc/passwd |
from:發送的郵件地址,對方顯示的發件人
smtp:發生的外部smtp服務器的地址
smtp-auth-user:外部smtp服務器認證的用戶名
smtp-auth-password:外部smtp服務器認證的用戶密碼
smtp-auth:郵件認證的方式
(2)sendEmail
簡介
http://www.ttlsa.com/linux/use-sendemail/
sendEmail是一個輕量級,命令行的SMTP郵件客戶端。如果你需要使用命令行發送郵件,那麼sendEmail是非常完美的選擇:使用簡單並且功能強大.這個被設計用在php、bash
perl和web站點使用。
以上是sendEmail的簡單介紹,千萬不要和sendmail搞混掉了。用了sendEmail你將不在喜歡sendmail了.
下載安裝sendEmail
1
2
3
4
|
# tar -xzvf sendEmail-v1.56.tar.gz //解壓後就可以使用了
# mv sendEmail /usr/local/bin/
|
發送郵件
命令說明:
發送成功之後會有如下提示:
Jul 29 15:02:53 e10074 sendEmail[26347]: Email was sent successfully!
sendEmail使用命令幫助
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
[root@li229-122 scripts]#
sendEmail --help
sendEmail-1.56 byBrandon
Zehm <caspian@dotconf.net>
Synopsis: sendEmail -f ADDRESS [options]
Required:
-f ADDRESS from (sender) emailaddress
* Atleast
onerecipient
requiredvia -t, -cc, or -bcc
* Messagebody
requiredvia -m, STDIN, or -o message-file=FILE
Common:
-t ADDRESS [ADDR ...] to emailaddress(es)
-u SUBJECT messagesubject
-m MESSAGE messagebody
-s SERVER[:PORT] smtpmail
relay, default is localhost:25
Optional:
-a FILE [FILE ...] fileattachment(s)
-cc ADDRESS [ADDR ...] cc emailaddress(es)
-bccADDRESS [ADDR ...] bcc
emailaddress(es)
-xu USERNAME username
for SMTPauthentication
-xp PASSWORD password
for SMTPauthentication
Paranormal:
-b BINDADDR[:PORT] localhost
bindaddress
-l LOGFILE logto thespecified
file
-v verbosity, use multipletimes
for greatereffect
-q bequiet (i.e. noSTDOUT
output)
-o NAME=VALUE advanced
options, for detailstry: --helpmisc
-o message-content-type=<auto|text|html>
-o message-file=FILE -o message-format=raw
-o message-header=HEADER -o message-charset=CHARSET
-o reply-to=ADDRESS -o timeout=SECONDS
-o username=USERNAME -o password=PASSWORD
-o tls=<auto|yes|no> -o fqdn=FQDN
Help:
--help thehelpful
overviewyou'rereading
now
--helpaddressing
explain addressingand relatedoptions
--helpmessage explainmessage
bodyinput
and relatedoptions
--helpnetworking
explain -s, -b, etc
--helpoutput
explain loggingand otheroutput
options
--helpmisc
explain -o options, TLS, SMTPauth, and more
|
sendEmail腳本發送
vim mail.sh #!/bin/bash to=$1 subject=$2 body=$3 server="smtp.exmail.qq.com" user="[email protected]" pwd="Tsdyosds" /usr/local/bin/sendEmail -f [email protected] -t "$to" -s $server -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu $user -xp $pwd -m "$body" 2>>/tmp/22.log ./mail.sh [email protected] 1212 xxx |
前言
linux 系統中常見的郵件發送服務有sendmai 和sendEmail 兩個是完全不同的東西
(1)sendmail
簡介
Linux服務器mail程序本身就是調用sendmail來進行郵件發送的,sendmail服務器提供對外的郵件發送功能。CentOS默認不能發送郵件,需要發送郵件的童鞋可以安裝一個sendmail程序
安裝
[root@ProxyServer ~]
# yum -y install sendmail
[root@ProxyServer ~]
# /etc/init.d/sendmail start
[root@ProxyServer ~]
# chkconfig sendmail on
[root@ProxyServer ~]
# man mail
使用
1、通過命令行發送郵件
第一行是輸入的命令,-s表示郵件的主題,後面的justin@51cto.com則是郵件的接收人,輸入完這行命令後回車,會進入郵件正文的編寫,可以輸入任何文字,比如上面的三行。當郵件正文輸入完成後,需要按CTRL+D結束輸入,此時會提示你輸入Cc地址,即郵件抄送地址,沒有直接回車就完成了郵件的發送。
2、使用管道進行郵件發送
echo "hello,echo"|mail -s "echo" [email protected]
3、使用文件進行郵件發送
mail -s "password" [email protected] < /etc/passwd
4、使用外部smtp(qq的SMTP)來發送郵件
bin/mail會默認使用本地sendmail發送郵件,這樣要求本地的機器必須安裝和啓動Sendmail服務,而通過修改配置文件/etc/mail.rc(/etc/nail.rc)可以使用外部SMTP服務器,可以達到不使用sendmail而用外部的smtp服務器發送郵件的目的。
[root@ProxyServer ~] # vim /etc/mail.rc #文末添加以下 [root@ProxyServer ~] # source /etc/mail.rc [root@ProxyServer ~] # mail -s "51cto" 15001*****@139.com < /etc/passwd |
from:發送的郵件地址,對方顯示的發件人
smtp:發生的外部smtp服務器的地址
smtp-auth-user:外部smtp服務器認證的用戶名
smtp-auth-password:外部smtp服務器認證的用戶密碼
smtp-auth:郵件認證的方式
(2)sendEmail
簡介
http://www.ttlsa.com/linux/use-sendemail/
sendEmail是一個輕量級,命令行的SMTP郵件客戶端。如果你需要使用命令行發送郵件,那麼sendEmail是非常完美的選擇:使用簡單並且功能強大.這個被設計用在php、bash
perl和web站點使用。
以上是sendEmail的簡單介紹,千萬不要和sendmail搞混掉了。用了sendEmail你將不在喜歡sendmail了.
下載安裝sendEmail
1
2
3
4
|
# tar -xzvf sendEmail-v1.56.tar.gz //解壓後就可以使用了
# mv sendEmail /usr/local/bin/
|
發送郵件
命令說明:
發送成功之後會有如下提示:
Jul 29 15:02:53 e10074 sendEmail[26347]: Email was sent successfully!
sendEmail使用命令幫助
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
[root@li229-122 scripts]#
sendEmail --help
sendEmail-1.56 byBrandon
Zehm <caspian@dotconf.net>
Synopsis: sendEmail -f ADDRESS [options]
Required:
-f ADDRESS from (sender) emailaddress
* Atleast
onerecipient
requiredvia -t, -cc, or -bcc
* Messagebody
requiredvia -m, STDIN, or -o message-file=FILE
Common:
-t ADDRESS [ADDR ...] to emailaddress(es)
-u SUBJECT messagesubject
-m MESSAGE messagebody
-s SERVER[:PORT] smtpmail
relay, default is localhost:25
Optional:
-a FILE [FILE ...] fileattachment(s)
-cc ADDRESS [ADDR ...] cc emailaddress(es)
-bccADDRESS [ADDR ...] bcc
emailaddress(es)
-xu USERNAME username
for SMTPauthentication
-xp PASSWORD password
for SMTPauthentication
Paranormal:
-b BINDADDR[:PORT] localhost
bindaddress
-l LOGFILE logto thespecified
file
-v verbosity, use multipletimes
for greatereffect
-q bequiet (i.e. noSTDOUT
output)
-o NAME=VALUE advanced
options, for detailstry: --helpmisc
-o message-content-type=<auto|text|html>
-o message-file=FILE -o message-format=raw
-o message-header=HEADER -o message-charset=CHARSET
-o reply-to=ADDRESS -o timeout=SECONDS
-o username=USERNAME -o password=PASSWORD
-o tls=<auto|yes|no> -o fqdn=FQDN
Help:
--help thehelpful
overviewyou'rereading
now
--helpaddressing
explain addressingand relatedoptions
--helpmessage explainmessage
bodyinput
and relatedoptions
--helpnetworking
explain -s, -b, etc
--helpoutput
explain loggingand otheroutput
options
--helpmisc
explain -o options, TLS, SMTPauth, and more
|
sendEmail腳本發送
vim mail.sh #!/bin/bash to=$1 subject=$2 body=$3 server="smtp.exmail.qq.com" user="[email protected]" pwd="Tuzhuyou3498" /usr/local/bin/sendEmail -f [email protected] -t "$to" -s $server -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu $user -xp $pwd -m "$body" 2>>/tmp/22.log ./mail.sh [email protected] 1212 xxx |