CentOS mail (sendmail/mstmp) method summary

Source: Internet
Author: User
Tags bz2 test email address

Let's take a look at the sendmail mail configuration..

Install sendmail
Run:

The code is as follows: Copy code

? 1 [root @ vps478753 ~] # Yum-y install sendmail

The program will automatically search for the sendmail installer for automatic installation.

After installing sendmail, run the following command to start sendmail.

The code is as follows: Copy code

? 123 [root @ vps478753 ~] # Service sendmail start Starting sendmail: [OK] Starting sm-client: [OK]

 
After starting, we can run the mail command to test whether emails can be sent.
1. Send an email through the file content

First, create a body.txt

The code is as follows: Copy code

[Root @ vps478753 ~] # Touch body.txt

Write content

The code is as follows: Copy code

[Root @ vps478753 ~] # Echo 'this is test mail'> body.txt

Send email

The code is as follows: Copy code

[Root @ vps478753 ~] # Mail-s 'test mail' mail@lizhong.me <body.txt


Click to open the content of body.txt.

This is test mail
 
2. Use the MPs queue to directly send the email content

If you do not want to send the email content through the file, you can also send it like this.

The code is as follows: Copy code

[Root @ vps478753 ~] # Echo "This is test mail" | mail-s 'test mail' mail@lizhong.me

If mail: command not found is prompted
[Root @ vps478753 ~] # Mail-s 'test mail' mail@lizhong.me <body.txt-bash: mail: command not found

The mail command is not installed. In this case, the mail command must be installed.

The code is as follows: Copy code

[Root @ vps478753 ~] # Yum install mailx-y

Then try again to send the following email!


Send email with mutt

1. Install and configure msmtp

1. Download and decompress msmtp

First use putty and other tools to log on to ssh

The code is as follows: Copy code

Wget http://downloads.sourceforge.net/msmtp/msmtp-1.4.16.tar.bz2? Modtime = 1217206451 & big_mirror = 0

Tar jxvf msmtp-1.4.16.tar.bz2

2. Installation

The code is as follows: Copy code

./Msmtp-1.4.16/configure -- prefix =/usr/local/msmtp
Make
Make install

Note that the directory marked in red is extracted to that directory. I don't know why yum cannot be used for direct installation. An error is prompted.

3. Configure an msmtp account

Switch to, cd/usr/local/msmtp

Create folder etc, mkdir etc

Use vi to create a file and enter vi/usr/local/msmtp/etc/msmtprc. The edit content is as follows:

The code is as follows: Copy code

# Set default values for all following accounts.
ULTS

Logfile/usr/local/msmtp. log
# The SMTP server of the provider.
Account test@163.com

# SMTP mail server address
Host smtp.163.com

# Email sent
From test@163.com
Auth login

# Email server logon account
User xiaobaichi@i0554.com

# Email server login password
Password 123456
# Set a default account
Account default: test@163.com


Esc, shift +: enter command mode, enter wq, save and exit.

Because the password is a plaintext, we need to modify the chmod 600. msmtprc permission for this file.

4. Test

The code is as follows: Copy code

/Usr/local/msmtp/bin/msmtp youremail@test.com

Enter any character and press Ctrl + D to exit and check whether the email is received.

With logs set, you can go to/usr/local/msmtp. log to view the logs. The success or failure of sending emails will be recorded.

You can send an email through the above steps. Here, the email is still sent using SMTP, and msmtp is equivalent to a third-party tool.

II. Install and configure mutt

1. mutt is installed by default in Linux, and CentOS is no exception.

You can use which mutt to view the mutt installation path. If not, use # yum install mutt.

3. Test whether mutt is valid.

The code is as follows: Copy code

Echo "test" | mutt-s "test" test email address

Echo "test" | mutt-s "my_first_test" yangcheng@i0554.com

Sent successfully after testing.

Note: After testing again just now, you do not need to install msmtp. You can directly install mutt to send an email, so that even if you do not have an SMTP account, you can also send an email as usual, COOL

Related Article

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.