Got error like error loading python script while sending mail using python with uipath

got error loading python script while sending mail using python with uipath

@Lucia_Singarayar

Welcome to fourms

Can you be more detail?

May i know Why are you using python to send the mails, you can use Send SMTP Mail activity

Thanks

mail was sending using python script. while python script integrated with uipath, got error like “Error loading Python script”

mail.py

import sys
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email import encoders
from mailClass import headerContentTxt
from mailClass import headerContentImg
from mailClass import headerContentZip
from mailClass import sendMail
#from mail import headerContentImg

sys.path.append(os.path.dirname(os.path.realpath(file)))

global msg
msg = MIMEMultipart()

def mainFunction(fromaddr,toaddr,body,ImgFileName,FileLoc,typeofmail,subject,pwd):

msg['From'] = fromaddr 
msg['To'] = toaddr
msg['Subject'] = subject
print("start"+typeofmail)
if(typeofmail=="text"):
	headerContentTxt(msg,body,FileName,FileLoc)
elif(typeofmail=="Image"):
	headerContentImg(msg,FileName,FileLoc)
elif(typeofmail=="Zip"):
	headerContentZip(msg,body,FileName,FileLoc)	
sendMail(msg,body,fromaddr,toaddr,pwd)
return "sucess" 

mailClass.py
import os
import sys
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email import encoders
sys.path.append(os.path.dirname(os.path.realpath(file)))

def headerContentImg(msg,FileName,FileLoc):
file=FileLoc+"/"+FileName
img_data = open(file, ‘rb’).read()
text = MIMEText(“test”)
msg.attach(text)
image = MIMEImage(img_data, name=os.path.basename(FileName))
msg.attach(image)

def headerContentTxt(msg,body,FileName,FileLoc):
msg.attach(MIMEText(body, ‘plain’))
#FileName = “sample.pdf”
file=FileLoc+"/"+FileName
attachment = open(file,“rb”)
p = MIMEBase(‘application’, ‘octet-stream’)
p.set_payload((attachment).read())
encoders.encode_base64§
p.add_header(‘Content-Disposition’, “attachment; filename= %s” % FileName)
msg.attach§

def headerContentZip(msg,body,FileName,FileLoc):
msg.attach(MIMEText(body, ‘plain’))
filename = FileName
#“test.zip”
file=FileLoc+"/"+FileName
attachment = open(file,“rb”)
p = MIMEBase(‘application’, ‘octet-stream’)
p.set_payload((attachment).read())
encoders.encode_base64§
p.add_header(‘Content-Disposition’, “attachment; filename= %s” % filename)
msg.attach§

def sendMail(msg,body,fromaddr,toaddr,pwd):

#"Python Subject of the Mail"	
s = smtplib.SMTP('smtp.gmail.com', 587) 
s.starttls() 
s.login(fromaddr, pwd) 
text = msg.as_string() 
s.sendmail(fromaddr, toaddr, text) 
s.quit()

I am learning python and uipath. so I have tried to integrate python with uipath. I have run some other scripts, its working.

Hi Guys,

Please anyone help me to rectify this issue.