linux mail 命令 (收發郵件)__linux

來源:互聯網
上載者:User

Ubuntu:
首先安裝mail
sudo apt-get install mailx
再次安裝postfix sudo apt-get install postfix (安裝過程中要進行配置,按照提示即可完成)
發送郵件命令樣本 cat "content"| mail -s "subject" yl33643@126.com

Debian / Ubuntu 系統 apt-get install mutt apt-get install swaks apt-get install mailx apt-get install sharutils

在基於Red Hat的系統,如CentOS 或者Fedora yum install mutt yum install swaks yum install mailx yum install sharutils


echo "This is the body"| mutt -s "Subject" test@example.com.cn

sendmail的配置宏檔案:/etc/mail/sendmail.mc

vi  /etc/mail/sendmail.mc

sharutils:(uuencode) 2 send attachments

1. 如何查看linux的mailqueue
$mailq
$sendmail -bp
$ll /var/spool/mqueue  這是mail隊列存放的目錄,可以將裡面的檔案刪除來清空mailqueue
可以通過這些命令來查看郵件是否送出

 

2. 如何發送mail
1)將檔案當做電子郵件的內容送出
文法:mail -s “主題”使用者名稱@地址< 檔案
例如:
$mail -s "send with content that is a file" sherry@geminimobile.com < install.log
2)傳送mail給本系統使用者
$mail 使用者名稱
3)編輯郵件內容
$mail sherry@geminimobile
Subject: messge for job  編輯標題後斷行符號
Apple this job. 開始編輯內容,結束後按Ctrl+D退出內容編輯
Cc:     輸入cc地址,如果沒有可以直接斷行符號將郵件發送出去
註:Ctrl+C可以中斷郵件編輯
4)快速發送郵件
$echo “郵件內文” | mail -s 郵件主題 sherry@geminimobile.com
5)發送附件
$uuencode 附件名 顯示附件名 | mail -s "subject" sherry@geminimobile.com
註:uuencode是將二進位檔案轉換為文字檔的過程,轉換後的檔案可以通過純文字e-mail進行傳輸,在接收方對該檔案進行uudecode,即將其轉換為初始的二進位檔案。

6)發送郵件時增加-v選項可以在終端看到郵件伺服器的response

[root@tc-40432-5s ~]# mail -v -s "send with content that is a file" sherry@geminimobile.com < install.log
sherry@geminimobile.com... Connecting to [127.0.0.1] via relay...
220 localhost.localdomain ESMTP Sendmail 8.13.1/8.13.1; Mon, 13 Dec 2010 14:40:13 +0800
>>> EHLO localhost.localdomain
250-localhost.localdomain Hello tc-40432-5s [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From:<root@localhost.localdomain> SIZE=60054 AUTH=root@localhost.localdomain
250 2.1.0 <root@localhost.localdomain>... Sender ok
>>> RCPT To:<sherry@geminimobile.com>
>>> DATA
250 2.1.5 <sherry@geminimobile.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 oBD6eDwW006082 Message accepted for delivery
sherry@geminimobile.com... Sent (oBD6eDwW006082 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 localhost.localdomain closing connection

 

3. 系統收到的mail會儲存在/var/spool/mail/使用者名稱 檔案夾中
收mail,鍵入mail就會顯示目前使用者的前20封mail。可對郵件進行查看刪除等操作。鍵入。可顯示所有命令
$mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 37 messages 37 new
>N  1 root@localhost.local  Mon Dec 13 11:55  21/940   "Cron <root@tc-40432-5s>       /usr/sbin/logrotate /usr/local/gemini/hss/3.0.0-ga1/etc/logrotate-stats/hss-stats-rotate"
.
.
.
& ?
    Mail   Commands
t <message list>                type messages
n                               goto and type next message
e <message list>                edit messages
f <message list>                give head lines of messages
d <message list>                delete messages
s <message list> file           append messages to file
u <message list>                undelete messages
R <message list>                reply to message senders
r <message list>                reply to message senders and all recipients
pre <message list>              make messages go back to /usr/spool/mail
m <user list>                   mail to specific users
q                               quit, saving unresolved messages in mbox
x                              

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.