cancel
Showing results for 
Search instead for 
Did you mean: 

Add file to mail on a workflow

Add file to mail on a workflow

Jose_Chaves
New Contributor II

Hi,

How can I add a file to mail in a workflow.

 

Regards,

JChaves

 

1 ACCEPTED SOLUTION

StephanH
Valued Contributor III

The File is put to the location configured with the variable “FilePath”. Per default it is /tmp.

Have a look to the workflow Variables.

Regards Stephan

View solution in original post

6 REPLIES 6

Jose_Chaves
New Contributor II

Hi,

In the extreme git there are some workflows, like the Aggregate report Alarm History, were you generate for example a csv file, and then in mail activity you send the mail with the csv file in attached.

What I don’t understand is who to put the csv file in the mail activity.

 

Regards,

José Chaves

StephanH
Valued Contributor III

Hello Jose,

as far as I know that’s not possible with onboard resources but you can use tools from python. Here is a working example with smtplib:

 

import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.mime.base import MIMEBasefrom email import encodersimport os.pathemail = 'sender@domain.com'send_to_email = 'receiver1@domain.com,receiver1@domain.com'subject = 'My message'message = 'My text'file_location = '/var/log/myAttachment.txt'msg = MIMEMultipart()msg['From'] = emailmsg['To'] = send_to_emailmsg['Subject'] = subjectmsg.attach(MIMEText(message, 'plain'))# Setup the attachmentfilename = os.path.basename(file_location)attachment = open(file_location, "rb")part = MIMEBase('application', 'octet-stream')part.set_payload(attachment.read())encoders.encode_base64(part)part.add_header('Content-Disposition', "attachment; filename= %s" % filename)# Attach the attachment to the MIMEMultipart objectmsg.attach(part)server = smtplib.SMTP('1.1.1.1',25)text = msg.as_string()server.sendmail(email, send_to_email.split(','), text)server.quit()

 

Regards Stephan
GTM-P2G8KFN