Python Script if you have to attach a file
___________
#! /usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import argparse
parser = argparse.ArgumentParser(description="Send emails with attached files",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,argument_default=argparse.SUPPRESS)
parser.add_argument("-s", "--smtp", help="Mailrelay IP",required=True)
parser.add_argument("-r", "--fromm", help="from",required=True)
parser.add_argument("-d", "--to", help="to",required=True)
parser.add_argument("-t", "--Subject", help="Subject",required=True)
parser.add_argument("-x", "--file", help="file to attacha",required=True)
args = parser.parse_args()
sender_email = args.fromm
receiver_email = args.to
message = MIMEMultipart()
message["From"] = args.fromm
message['To'] = args.to
message['Subject'] = args.Subject
file = args.file
attachment = open(file,'rb')
obj = MIMEBase('application','octet-stream')
obj.set_payload((attachment).read())
encoders.encode_base64(obj)
obj.add_header('Content-Disposition',"attachment; filename= "+file)
message.attach(obj)
my_message = message.as_string()
email_session = smtplib.SMTP(args.smtp,25)
email_session.starttls()
email_session.sendmail(sender_email,receiver_email,my_message)
email_session.quit()
___________
chmod +x mail.py
./mail.py -s x.x.x.x -r test@test.com -d elpana@siva.com -t "test email " -x file.csv