As a tool for system interaction with users, mail plays an important role. the system or program can put some key events or messages in mail for users to view. As a linux script developer and system maintenance personnel, learn about mail commands and send emails using sendmail.
As a tool for system interaction with users, mail plays an important role. the system or program can put some key events or messages in mail for users to view. As a linux script developer and system maintenance personnel, it is essential to understand the mail command and use sendmail to send emails.
1. View emails via mail
Enter mail in the command line
[Boco @ redhat5 ~] $ MailMail version 8.1 6/6/93. Type? For help. "/var/spool/mail/boco ": 2 messages 2 new> N 1 root@redhat5.4-baby Fri Feb 14 18/600 "hello boco" N 2 root@redhat5.4-baby Fri Feb 14 17/567 &? Mail Commandst
Type messages: displays the specified email n goto and type next messagee.
Edit messagesf
Give head lines of messagesd
Delete messages delete a specified email,
You can use d 2-100 to delete 2nd to 100 emails.S
File append messages to file write to file u
Undelete messagesR
Reply to message sendersr
Reply to message senders and all recipientspre
Make messages go back to/usr/spool/mail m
Mail to specific usersq quit, saving unresolved messages in mbox
Save the emails you have viewed ~ /Mbox. If pre is executed, it is not saved.X quit, do not remove system mailbox
The effect does not seem to have been seen.H print out active message headers
Show email list! Shell escape executes the command cd [directory] chdir to directory or home if none givenA
Consists of integers, ranges of same, or user names separatedby spaces. If omitted, Mail uses the last message typed.
Consists of user names or aliases separated by spaces. Aliases are defined in. mailrc in your home directory .&
If the email is received and placed in ~ /Mbox can view them as follows:
# mail -f ~/mbox
2. send internal emails
Mail-s "hi, boco, I'm root" boco <email content
Or
Mail-s "hi, boco, I'm root" snail il
Plz reply me, snail il.
.
Cc:
Note]Use. or Ctrl + D or. to end the content input
Note]By default, the work is interrupted by pressing Ctrl + C twice.
3. send external emails
Mail-s "fff"God_is_coming@163.com
This is sent using the current username @ host name as the username.
Because the mail has to rely on sendmail to deliver the mail, according to the online information, you can check if sendmail has any emails to be sent. if not, it indicates that all emails have been sent. (Of course, yourThe sendmail service must be on)
[root@pps ~]# sendmail -bp /var/spool/mqueue is empty Total requests: 0
Online usageSendmail can send external emails with a specific user name.But I did not try it on redhat 5.4. However, the following method can be used.
Download new sendEmail
SendEmail homepage http://caspian.dotconf.net/menu/Software/SendEmail/
Http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
Decompress and run
# Tar-zxvf sendEmail-v1.56.tar.gz
# Cd sendEmail-v1.56
Then confirm that it has the execution permission.
[Root @ redhat5 sendEmail-v1.56] #. /sendEmail-f god_is_coming@163.com-t weichaofan@boco.com.cn-u "from sendmail"-xu god_is_coming@163.com-xp ××× (password) -m happy3-s smtp.163.com Feb 14 13:15:19 redhat5 sendEmail [684]: Email was sent successfully! [Root @ redhat5 sendEmail-v1.56] #Explanation:-f indicates the sender's email address.-T indicates the recipient's email address.-S indicates the domain name or ip address of the SMTP server.-u indicates the subject of the email.-xu indicates the user name for SMTP verification.-xp indicates the password for SMTP Authentication. (no special characters are allowed) -m indicates the Mail content
If you do not include the-m parameter, you will be prompted to enter
Reading message body from STDIN because the '-M' option was not used.
If you are manually typing in a message:
-First line must be received within 60 seconds.
-End manual input with a CTRL-D on its own line
End with CTRL-D after input is complete
Of course we can.Send the content of a file as the body of the emailOf
Then you can use:
Cat file name |/usr/local/bin/sendEmail-f sender@163.com-t receiver@163.com-s smtp.163.com-u "subject"-xu sender-xp 123456-m happy