How to use scripts to automatically send text mail in linux

Source: Internet
Author: User
Article title: analyze how to use scripts to automatically send text mail in linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1. install msmtp

Luther @ gliethttp :~ $ Sudo apt-get install msmtp

2. edit the configuration script (~ /. Msmtprc is the default configuration file, or you can use the-C option to specify the configuration file path)

Luther @ gliethttp :~ $ Vim msmtprc

# Add the following content

ULTS

# Logfile/home/luther/msmtp. log

Account luther_test

Host mail.gliethttp.cn

From luther@gliethttp.cn

Auth off

Password 123456789

Account default: luther_test

3. remove the execution permission of the configuration file-x

Luther @ gliethttp :~ $ Chmod 600 msmtprc

4. now, you can use the following statement to send a test email to your mailbox, or enter it on stdin, and then press ctrl + D.

Some data in the file may be lost, not afraid. after mutt is installed, everything will be normal.

Luther @ gliethttp :~ $ Msmtp luther@gliethttp.cn-C/home/luther/msmtprc </vobs/tmp/log. c

5. install mutt.

Luther @ gliethttp :~ $ Sudo apt-get install mutt

6. edit the configuration script (~ /. Muttrc is the default configuration file. you can also use the-F option to specify the path of the configuration file)

Luther @ gliethttp :~ $ Vim muttrc

# Add the following content

Set sendmail = "/usr/bin/msmtp-C/home/luther/msmtprc"

Set use_from = yes

Set from = admin@gliethttp.cn

Set realname = "test admin"

Set editor = "vim"

7. send common text and file content

Luther @ gliethttp :~ $ Echo "test 123abc" | mutt-F/home/luther/muttrc-s "Mail title-test" luther@gliethttp.cn

Luther @ gliethttp :~ $ Mutt-F/home/luther/muttrc-s Mail title-test luther@gliethttp.cn </etc/passwd

8. send the attachment (-a option is used to add the attachment. the following example adds the attachment passwd and resolv. conf)

Luther @ gliethttp :~ $ Echo "test 123abc" | mutt-F/home/luther/muttrc-s "Mail title-test" luther@gliethttp.cn-a/etc/passwd-a/etc/resolv. conf

9. send the bcc address and cc address. use commas to separate multiple email addresses.

Luther @ gliethttp :~ $ Echo "test 123abc" | mutt-F/home/luther/muttrc-s"

Mail title-test "luther@gliethttp.cn, luther.ge@163.com-B luther.ge@163.com, luther@gliethttp.cn-c luther.ge@163.com, luther@gliethttp.cn

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.