I. Basic Environment 1, version cat /etc/debian_version 7.82, kernel uname -r3.2.0-4-amd643, IP (eth0) 10.1.10.1854, specific log cat 3.logaaa 10-29_10:30 29629395 testbbb 10-29_10:36 180035 testccc 10-29_10:37 180035 testddd 10-29_10:37 580495 testeee 10-29_10:37 580495 testfff 10-29_10:46 180035 testggg 10-29_10:46 180035 &NBSP;&NBSP;&NBSP;TEST5, mutt use is hairTo 163 of the python is used in the company 6, the use of the Python version is 2.7 Two, the specific code cat mailsend.sh #!/bin/bash#------------------------ --------------------------#Author: jimmygong#email:[email protected] #FileName: mailsend.sh#function: # version:1.0 #Created: 2015-10-30#--------------------------------------------------sendip= "10.1.10.185" Maillog= "/root/3.log" mailbox= "[email protected]" function handlemail () { sed -i -e ' 1i\title1\ttitle2\ttitle3\tdtitle4 ' $maillog sed -i -e ' s/^/<tr><td>/' -e ' s/\s\+/<\/td><td>/' -e ' s/\s\+/ <\/td><td>/' -e ' s/\s\+/<\/td><td>/' -e ' s/$/<\/td><\/tr >/' $maillog sed -i -e ' 1i\<table> ' -e ' $a \</ Table> ' $maillog sed -i -e ' 1i\<style type= "Text\/css" >table,td,th{bOrder:1px solid black;} <\/style> ' $maillog /usr/local/mutt/bin/mutt -s "aaa $sendip" -e ' set content_type= ' text/html ' $mailbox < $maillog #python mailsend.py $maillog "aaa $sendip"}handlemailexit 0ps:1, if using mutt then please refer to the following link to install http://7938217.blog.51cto.com/7928217/16418032, if using Python then use the following Python code
cat mailsend.py
#!/usr/bin/python# -*- coding: utf-8 -*-#------------------------------------------------- -#Author: jimmygong#email:[email protected] #FileName:mailsend.py#function: #Version:1.0 #Created : 2015-10-30#--------------------------------------------------Import sysimport smtplib from email import encodersfrom email.mime.base import MIMEBasefrom email.mime.text import mimetextfrom email.utils import commaspacefrom Email.mime.multipart import mimemultipartdef send_mail (fro,to,subject,text,txttype= ' HTML ', files =[]): msg = mimemultipart () msg[' from '] = fro msg[' Subject '] = subject msg[' to '] = commaspace.join (to) if txttype== "HTML": msg.attach (Mimetext (text, ' HTML ')) else: msg.attach (Mimetext (text)) for file in files: part = mimebase ( ' Application ', ' Octet-stream ') part.set_payload (open (file, ' R '). Read ()) encoders.encode_base64 (part) part.add_header (' content-disposition ', ' attachment; Filename= "%s" ' % os.path.basename (file) Msg.attach (part) s = smtplib. SMTP () s.connect (' mail.shidc.taomee.com ') s.sendmail (Fro,to, Msg.as_string ()) s.quit () if __name__== ' __main__ ': fro= ' [email protected] ' to=[' [email protected] ',] Subject=sys.argv[2] with open (Sys.argv[1], "R") as f: text=f.read () txttype= ' HTML ' files=[] send_mail (Fro,to,subject,text,txttype,files)
3, some instructions sys.argv[] is used to get command line arguments, Sys.argv[0] represents the code itself file path, so the parameters start from 1. Third, the effect
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/43/wKiom1Yzg9mDKHnvAAGd2JNm49A050.jpg "title=" Bbb.png "alt=" Wkiom1yzg9mdkhnvaagd2jnm49a050.jpg "/>
This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1708228
Send HTML-formatted messages (Shell+python)