1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/usr/bin/python
import os
import sys
import smtplib
import ConfigParser
from email.MIMEText import MIMEText
def PrintUsage():
print( "Usage: %s < Ticket_Number >" ) % ( sys.arg[0] )
sys.exit(1)
def EmailSending( p_MailGateway, p_Sender, p_Recipient_To, p_Recipient_Cc, p_Subject, p_Body ):
""" This function receives server, sender, recipient, subject and body to construct mail and sends it """
Email = MIMEText(p_Body)
Email['From'] = p_Sender
Email['To'] = p_Recipient_To
Email['Cc'] = p_Recipient_Cc
Email['Subject'] = p_Subject
l_Recipient = p_Recipient_Cc.split(",")
l_Recipient.append( p_Recipient_To )
SmtpLink = smtplib.SMTP(p_MailGateway)
SmtpLink.sendmail(Email['From'], l_Recipient, Email.as_string())
SmtpLink.quit()
if __name__ == "__main__":
l_Config = ConfigParser.ConfigParser()
l_ConfigFile = os.path.join( os.path.dirname( __file__ ), "config.cfg" )
l_Config.read( l_ConfigFile )
l_MailGateway = l_Config.get( "General", "MailGateway" )
l_Recipient_To = l_Config.get( "General", "Recipient_To" )
l_Recipient_Cc = l_Config.get( "General", "Recipient_Cc" )
l_Sender = l_Config.get( "General", "Sender" )
l_Subject = l_Config.get( "General", "Subject")
if ( len( sys.argv ) < 2 ):
PrintUsage()
else:
l_Body = """Dear all,
A priority 1 has been opened. Its ticket number is: %s """ % ( sys.argv[1] )
EmailSending( l_MailGateway, l_Sender, l_Recipient_To, l_Recipient_Cc, l_Subject, l_Body ) |
Partager