#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
emailto=itsm.getParameter('EmailTo')  ## Provide an Toemail address where the mail need to be sent.You can also provide any number of To eamil address For example: ['varun@yopmail.com', xxxx@yopmail.com]
emailfrom=itsm.getParameter('EmailFrom')  ## Provide the From Email address from which the mail to be send
password=itsm.getParameter('Password')               ##Provide password for from email
smtpserver='smtp.gmail.com'
port=587

import os,sys,shutil,re,sys,socket,_winreg,random,getpass
from datetime import date, datetime
import socket
import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.message import Message
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import ctypes
from subprocess import PIPE, Popen

def computername():
    return os.environ['COMPUTERNAME']

def ipaddress():
    return socket.gethostbyname(socket.gethostname())

subject='%s %s Alert : Patch Report!!!!!'%(computername(), ipaddress())		

def emailreport(subject, emailto,emailfrom,password,smtpserver,port,msgbody,fileToSend):
	msg = MIMEMultipart()
	msg["From"] = emailfrom
	msg["To"] = ",".join(emailto)
	msg["Subject"] = subject
	msg.preamble = subject
	body = MIMEText(msgbody)
	msg.attach(body)    
	with open(fileToSend) as fp:
		record = MIMEBase('application', 'octet-stream')
		record.set_payload(fp.read())
		encoders.encode_base64(record)
		record.add_header('Content-Disposition', 'attachment',
		filename=os.path.basename(fileToSend))
		msg.attach(record)
	try:
		server = smtplib.SMTP(smtpserver,port)
		server.ehlo()
		server.starttls()
		server.login(emailfrom, password)
		server.sendmail(emailfrom, emailto, msg.as_string())
		server.quit()
		return " \nThe email report has been sent to "+msg["To"]
	except Exception as e:
		return e
temp=os.environ['TEMP']+'\\output.txt'
command=r'powershell.exe  Get-Hotfix >'+temp #Please edit your comand here.
def ecmd(command):
	obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
	out, err = obj.communicate()
	if err:
		print err
	else:
		fileToSend=temp
		msgbody="""
		Hi,
		
		The Report File has been attached
		"""
		print emailreport(subject,emailto,emailfrom,password,smtpserver,port,msgbody,fileToSend)
		
ecmd(command)