Ubuntu Linux automatic mail configuration and mail sending Script test environment: Ubuntu 11.10 1. install mutt and msmtp software [plain] sudo apt-get install mutt sudo apt-get install msmtp 2. edit the configuration file vi ~ /. Muttrc [plain] set sendmail = "/usr/bin/msmtp" set use_from = yes set realname = "Guobao Jiang" set from = loveaborn@163.com set envelope_from = yes 3. edit the configuration file vi ~ /. Msmtprc (change the account and password accordingly. You 'd better change the file attribute to [plain] chmod 700 ~ /. Msmtprc others cannot modify and view) [plain] account default host smtp.163.com from loveaborn@163.com auth plain user loveaborn password #### logfile ~ /. Msmtp. log 4. Write the automatic mail sending script as follows: [plain] #! /Bin/bash #################################### ######################################## ########## this shell script is used to send mail automatically # the root structure is #. #. /autosend. sh -- this shell script #. /attach/-- this folder stored mail's all attachment. #. /bak/-- for backup #. /log/-- send & unsend log files #. /mail/-- mail text content, default file name '. /mail. md '#. /Readme. md -- readme file (not mandatory) # version: v0.1 @ Aug. 4, 2013, by Guobao Jiang ##################################### ######################################## ######### dateInfo = "$ (date + % Y-% m-% d-% H-% M-% S) "attachName =" attach_Info.tar.gz "; contentFile = ". /mail. md "toName =" loveaborn@foxmail.com "ccName =" loveaborn@163.com "if [-f. /mail. md]; then if [! -F. /log/send. log]; then touch. /log/send. log fi sendLog = ". /log/send. log "tar zcvf $ attachName. /attach sleep 2 rm-rf. /attach/* mkdir-p ". /bak/mail _ $ dateInfo "cp $ attachName ". /bak/mail _ $ dateInfo "cp. /mail. md ". /bak/mail _ $ dateInfo "echo-e" "> $ contentFile echo-e" ---------------- ">>> $ contentFile echo-e" Note: this mail is automaticall by my server. ">>> $ contentFile echo-e" BR // G Uobao Jiang (loveaborn@foxmail.com) "> $ contentFile echo-e" DateRecord: $ dateInfo "> $ contentFile echo-e" ">" $ sendLog "echo-e" ----------------------------------- ">" $ sendLog "echo-e" Sending mail... ">" $ sendLog "mutt-s" Update Experiments Result $ dateInfo "-c $ ccName $ toName \-a $ attachName <" $ contentFile "if [$? -Eq 0]; then rm-rf $ attachName rm-rf. /mail. md # rm-rf. /attach/* # if success, delete all attachment files. echo-e "mail was sent to $ toName and cc to $ ccName successully! ">>\" $ SendLog "else rm-rf $ attachName rm-rf"./bak/mail _ $ dateInfo "echo-e" mail sent failed! Please try again! ">>" $ SendLog" fi echo-e "RecordTime: $ dateInfo" >>" $ sendLog "else if [! -F./log/record. log]; then touch./log/nosend. log fi echo-e "No mail contents to send! RecordTime: $ dateInfo ">>. /log/nosend. log fi Note 0: file autosend. sh, add the executable attribute [plain] chmod u + x autosend. sh Note 1: nearby-a $ attachName placed at the end, otherwise the following error will occur: [html] Can't stat loveaborn@foxmail.com: No such file or directory loveaborn@foxmail.com: unable to attach file. note 2: The content of my email is placed in. /mail. in the md file, remarks will be sent. /bak and delete the original file. The directory structure is as follows: