Linux Email mail Commands detailed _linux

Source: Internet
Author: User
Tags auth

Mail command

1. Configure

Vim/etc/mail.rc

Add the following content to the end of the file

Set from=1968089885@qq.com smtp= "smtp.qq.com"
set smtp-auth-user= "1968089885@qq.com" 123456 "
Set Smtp-auth=login

Description

From: The sender that appears when the other person receives the message

SMTP: Specifies the SMTP server address for a third party to send mail

Smtp-auth:smtp authentication method. The default is login, which can also be changed to CRAM-MD5 or plain mode

Smtp-auth-user: Third party email user name

Smtp-auth-password: User name corresponds to 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" Inbox address

% mail-s "Test" 1968089885@foxmail.com

2) have the message body

Mail-s "Subject" Inbox < files (message text. txt)

% mail-s "Mail Subject" 1968089885@foxmail.com </data/findyou.txt

echo "Message body" | Mail-s Mail Subject Address

% echo "message body content" | Mail-s "Mail Subject" 1968089885@foxmail.com

Cat message body. txt | Mail-s Mail Subject Address

% Cat/data/findyou.txt | Mail-s "Mail Subject" 1968089885@foxmail.com

3) with Accessories

Mail-s "Subject" address-a Attachment < file (message text. txt)

% mail-s "Mail Subject" 1968089885@foxmail.com-a/data/findyou.tar.gz </data/findyou.txt

3. Script

sendmail.sh

#!/bin/bash
 #author: Findyou help
 () {
  echo "eg: $ [Subject] [address] [content_file] [file]"
  echo "
  exit 1
 }

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" $]; then
   mail-s $ ${mail_to}<$3
else
   mail-s $ A $ ${mail_to}<$3
fi

Use

[root@123]$./sendmail.sh test 1968089885@qq.com abc.txt
    Send Mail to 1968089885@qq.com
 [root@123]$

Note: It is recommended to use the command directly, there are scripts just to display relevant information in print, superfluous.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.