linux mail 命令

來源:互聯網
上載者:User

linux mail 命令

--收發郵件

 

(2010-12-13 14:44:20)轉載自http://blog.sina.com.cn/sherryw2007
分類: Linux
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=60054AUTH=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                               quit, do not remove system mailbox
h                               print out active message headers
!                               shell escape
cd [directory]                  chdir to directory or home if none given
A <message list> consists of integers, ranges of same, or user names separated
by spaces.  If omitted, Mail uses the last message typed.
A <user list> consists of user names or aliases separated by spaces.
Aliases are defined in .mailrc in your home directory.
在linux文本命令平台輸入 mail -f mbox,就可以看到目前的目錄下的mbox中的郵件了。
cd 改變當前所在檔案夾的位置
讀信時,按一次Ctrl+C,退出閱讀狀態。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.