Linux email Mail

Source: Internet
Author: User
Tags smtp auth


1. Installation (requires SendMail or postfix service)
Sendmail
# yum install sendmail
# systemctl start sendmail.service
# systemctl status sendmail.service
Postfix
# yum install mailx
# systemctl start postfix.service
# systemctl status postfix.service
postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active (running) since 2 September 19, 2017 14:08:03 CST; 1s ago
Process: 72063 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
Process: 72060 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
Process: 72057 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
Main PID: 72136 (master)
CGroup: /system.slice/postfix.service
├─72136 /usr/libexec/postfix/master -w
├─72137 pickup -l -t unix -u
└─72138 qmgr -l -t unix -u
September 19 14:08:03 centos73 SYSTEMd [1]: starting postfix mail transport agent
September 19 14:08:03 centos73 postfix / Master [72136]: day started -- version 2.10.1, configuration / etc / Postfix
September 19 14:08:03 centos73 system d [1]: started postfix mail transport agent
Accessory Package: uuencode
yum install sharutils
Inspection:
netstat -tunlp |grep 25

2. Configuration
# vim /etc/mail.rc
Add the following at the end of the document
set [email protected] smtp="smtp.qq.com"
set smtp-auth-user="[email protected]" smtp-auth-password="rootroot"
set smtp-auth=login
Explain:
From: the sender displayed when the other party receives the message
SMTP: Specifies the SMTP server address of the third party sending mail
SMTP auth: authentication method of SMTP. The default is login, or cram-md5 or plan mode
SMTP auth user: user name of the third party sending mail
SMTP auth password: password corresponding to user name
Restart: (which to install and which to restart)
systemctl restart sendmail.service
systemctl restart postfix.service
3.Mail command
SMTP: simple mail transmission protocol: simple mail transmission protocol, sending mail;
POP3: Post Office Protocol
IMAP4: Internet Mail Access Protocol
Mail – s "mail subject" – C "CC address" – B "BCC address" -- F sender's email address – f sender's name < email content to be sent
Options:
-B < address >: specify the address of the addressee of the confidential copy;
-C < address >: specify the address of the addressee of the copy;
-F < mail file >: read the mail in the specified mail file;
-i: Do not display the information sent by the terminal;
-1: Use interactive mode;
-n: When using the program, do not use the settings in the mail.rc file;
-N: Do not display the title of the message when reading it;
-S < mail subject >: Specifies the subject of the mail;
-U < user account >: read the mail of the specified user;
-v: When executed, displays detailed information.
1) No message body
Mail-s subject to address
Mail-s "test" [email protected]
2) With message body
Mail - s subject to file (body. Txt)
Mail - s "mail subject" [email protected] < / data / findyou.txt
Echo "message body" | mail - s subject address
Echo "message body content" | mail - s "message subject" [email protected]
Cat message body.txt | mail - s message subject to address
Cat / data / findyou.txt | mail - s "mail subject" [email protected]
3) With accessories
Mail - s "subject" to - a attachment < file (message body. Txt)
Mail - s "mail subject" [email protected] - A / data / findyou.txt < / data / findyou.txt
Uuencode / data / findyou.txt | mail - s "mail subject" [email protected]
Generation of message body:
(1) Interactive input;
A single line of dots (.) can indicate the end of the text; a Ctrl + D submission can also indicate the end of the text;
Send emails
[[email protected] ~]# mail -s ‘hello hdfs‘ hdfs
How are you these days?
. the end of the dot indicates the end; then enter
EOT
[[email protected] ~]#
Receive mail
Mail
#Enter the number to view the corresponding email
Q ා Q exit
(2) Redirection by input;
Mail - s' hello HDFS' HDFS < file.txt (body content)
(3) Through pipes;
cat file.txt | mail -s ‘hello hdfs‘ hdfs
4. Scripts
# vim sendmail.sh
/bin/bash!
#author:findyou
Help () {
echo "eg: $0 [Subject] [address] [content_file] [file]"
Echo ""
Exit 1
}
if [ ! -n "$1" ] ; then
Help
Fi
cDate=`date +%Y%m%d`
if [ ! -n "$2" ] ; 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
# ./sendmail.sh  test  [email protected]  abc.txt
Send Mail to [email protected]
Note: it is recommended to use the command directly. If there is a script, it is only for printing and displaying relevant information. This is unnecessary.
5. Questions
Send mail:
#Echo 'this is the message title' | mail - s' this is the message content '[email protected]
Exception occurred:
# send-mail: fatal: parameter inet_interfaces: no local interface found for ::1
View postfix logs in CentOS
# more  /var/log/maillog
postfix: fatal: parameter inet_interfaces: no local interface found for ::1
# vi /etc/postfix/main.cf
inet_interfaces = localhost
inet_protocols = all
Change to:
inet_interfaces = all
inet_protocols = all
Restart: (which to install and which to restart)
# systemctl restart sendmail.service
# systemctl restart postfix.service 


This article is from the "Caterpillar Small Smelly Smelly" blog, please make sure to keep this source http://moerjinrong.blog.51cto.com/11124564/1966812



Linux email Mail


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.