1. Configuration
Vim/etc/mail.rc
Add the following to the end of the file
Set from=[email protected]smtp= "Smtp.qq.com"
Set smtp-auth-user= "[email protected]"Smtp-auth-password="123456 "
Set Smtp-auth=login
Description:From: The sender that appears when the other person receives the message
SMTP: Specify the SMTP server address for third-party outgoing messages
Smtp-auth:smtp authentication method. Default is login, can also be changed to CRAM-MD5 or plain mode
Smtp-auth-user: The user name of the third-party email
Smtp-auth-password: User name corresponding password
2.Mail command
% Mail--h
Mail:illegal option---
usage:mail-eiiudefntbdnhrv~-T file-u user-h hops-r address-s subject-a file-q file-f file-a account-b users-c Users-s OPTION Users
Note: Some system parameters are slightly different, it is best to see Help
1) No message body
- Mail-s "Subject" pickup address
% mail-s " test " 1968089885@foxmail. com
2) have the message body
- Mail-s "Subject" Pickup address < file (message body. txt)
% mail-s " Mail subject " 1968089885@foxmail. com </data/findyou.txt
- echo "Message body" | Mail-s Mail Subject Pickup Address
% echo " message body content " | Mail-s " Mail subject " 1968089885@foxmail. com
- Cat message body. txt | Mail-s Mail Subject Pickup Address
% Cat /data/findyou.txt | mail-s " Mail subject " 1968089885@foxmail. com
3) with accessories
- Mail-s "Subject" pickup address-a Attachment < file (message body. txt)
% mail-s " Mail subject " 1968089885@foxmail. Com-a/data/findyou. tar. gz </data/findyou.txt
3. Scripts
sendmail.sh
#!/bin/bash
#author: Findyou
Help () {
Echo "eg: $ [Subject] [address] [content_file] [file]"
Echo ""
Exit1
}
if[!-N" $"] ; Then
Help
fi
Cdate= 'Date+%y%m%d '
if[!-N" $"] ; Then
Help
Else
mail_to=$2
Echo "Send Mail to ${mail_to}"
fi
if[!-N"$4"] ; Then
Mail-s $1${mail_to}<$3
Else
Mail-s $1-A $4${mail_to}<$3
fi
Use
[[Email protected]123]$./sendmail.SHTest1968089885@qq. com abc.txt
Send Mail to1968089885@qq. com
[[Email protected]123]$
Description: It is recommended to use the command directly, there is script just to display relevant information in print, superfluous.
The Mail command for Linux email