def MailSender(filename,time): try: fromaddr = "*****@*****.**" toaddr = "*****@*****.**" msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr body = """ Hello %s, Welcome to this Script, Please find attached document which contains Log of Running process, Log file is created at:%s This is auto generated mail. Thanks & Regards, Abhishek Jagdish Joshi """%(toaddr,time) Subject = """ Process log generated at: %s """%(time) msg['Subject'] = Subject msg.attach(MIMEText(body,'plain')) attachment = open(filename,"rb") p = MIMEBase('application','octet-stream') p.set_patload((attachment).read()) encoders.encode_base64(p) p.add_header('Content-Dispositon',"attachment;filename=%s" % filename) msg.attach(p) s = smtplib.SMTP('smtp.gmail.com',587) s.starttls() # fromaddr is your mentioned email address and type your password in next underline s.login(fromaddr,"----------") text = msg.as_string() s.sendmail(fromaddr,toaddr,text) s.quit() print("Log file successfully sent through Mail.") except Exception as E: print("Unable to send mail.",E)