It is a problem to use sendmail In ubuntu. It is left blank when the topic is sent.
Simply install Mutt and msmtp and send an email through the 163 mail system.
Sudo apt-Get install mutt. In addition, you need to install msmtp, a small tool for sending emails, and sudo apt-Get install msmtp.
Configure mutt
1. Add the last five lines to the/etc/muttrc file.
Set Sendmail = "/usr/bin/msmtp"
Set use_from = Yes
Set realname = "mozatmonitor" --- "the sender displays the nickname
Set From = mozatmonitor@163.com -- sender address
Set envelope_from = Yes
----------------- If you have any Encoding Problems, try to add ----
Set charset = "UTF-8"
# Set send_charset = "gb2312"
Set send_charset = "UTF-8"
Set locale = "zh_CN.UTF-8"
Set content_type = "text/html \; charset = UTF-8"
2. Edit ~ /. Msmtprc. If the file does not exist, create one. to log on to the current user and group, the file requires 600 permissions. If the file does not have 600 permissions, it cannot be used.
Account default
Host smtp.163.com ----> email server address
From mozatmonitor@163.com
Auth login ------> the most silly login authentication method
User mozatmonitor
Password kkkkkk -----> kkkkkk with Password
Logfile ~ /. Msmtp. Log
Send:
Mutt-s "theme" foo@sina.com.cn-A attachment .txt <
Multiple contacts and attachments:
Maillist = 'cat list.txt'
/Usr/bin/mutt-s "topic" $ maillist-A Attachment 1-A Attachment 2
# Send alarm emails
1. Run the script to import data in the background (this script contains the computing script runtime): nohup./import. Sh &
123456789101112131415 |
At @ DellR410-DB4 :~ $ Cat Import . Sh #! /Bin/bash Begintime =' Date + "% Y-% m-% d % H: % m: % s"
` /Usr/local/mysql-5 . 5.15 /Bin/MySQL -H 127.0.0.1-P 3335-uxxx-pxxxxxx < /Home/snapshot at/xxx . SQL Endtime =' Date + "% Y-% m-% d % H: % m: % s" `
Begin_data =' Date -D "$ Begintime" + % S' # Convert the current time to Linux time End_data =' Date -D "$ Endtime" + % S' Spendtime =' Expr $ End_data-$ begin_data'
# Calculate the difference of two times Echo "It takes $ spendtime sec for dump the data directory" Echo "It takes $ spendtime sec for dump the data directory" > /Tmp/dump184_3335mofs2 . Txt |
2. Run the monitoring script every minute in the crontab. If the script is found to be running, send an email to 139, so that the mobile phone will receive a text message.
1234567891011 |
At @ DellR410-DB4 :~ $ Crontab -L * /1 **** /Bin/sh /Home/operation at/Operation/XX/sendmail . Sh At @ DellR410-DB4 :~ $ Cat /Home/operation at/Operation/XX/sendmail
. Sh #! /Bin/bash Counter =' PS -Ef | Grep Import . Sh | Grep - V Grep | WC
-L' If [$ Counter- EQ 0]; Then /Usr/bin/mutt -S "Back is finished" 13xxxxx@139.com /Home/operation at/Operation/XX/Hello . Txt Else
Echo "The backup is running now ." Fi |