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