Feb 08 2013

Mail Send With Python

Category: Linux & Unix,PythonFatih Acar @ 11:39

Mail Send Function | File name : sender.py

import string
import smtplib
from email.mime.text import MIMEText
def mailSend(subject,content):

mailserver = “192.168.5.2” # Mail Server IP Address

mail = MIMEText(content)

mail[“From”] = “fromaddress@example.com”

mail[“To”] = “toaddress@example.com”

mail[“Subject”] = subject

gonder = smtplib.SMTP(mailserver)

gonder.sendmail(mailfrom,mailto,mail.as_string())

gonder.quit()

Notification Example for Disk Status Check | File name : diskcheck.py

from sender import *
import os
import commands
def main():

subject = “Nodes Disk Status”

content = “Node 1” + ‘\n\n’

query = “df -h”

query = commands.getoutput(query)

query = query.split(‘\n’)

for answer in query:

content = content + answer + ‘\n’

query = “df -i”

query = commands.getoutput(query)

query = query.split(‘\n’)

content = content + ‘\n’

for answer in query:

content = content + answer+ ‘\n’

query = “ssh node2 df -h”

query = commands.getoutput(query)

query = query.split(‘\n’)

content = content + ‘\n\n’ “Node 2” + ‘\n\n’

for answer in query:

content = content + answer + ‘\n’

query = “ssh node2 df -i”

query = commands.getoutput(query)

query = query.split(‘\n’)

content = content + ‘\n’

for answer in query:

content = content + answer + ‘\n’

mailSend(subject,content)
main()

12,104 total views, 10 views today

Tags: Python, System Administration

facebook comments:

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.