List Icon
Mailing list Archive

2019 up to July 2022 | 20182017  |  2016  2015 2014 | 2013

The mailing list has been closed since July 2022, but continues to serve as an archive of information about QF-Test.
If you want to stay informed about news about QF-Test, you can simply subscribe to our newsletter:
Subscribe to Newsletter  

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[QF-Test] How to send email with an attachment.

  • Subject: [QF-Test] How to send email with an attachment.
  • From: "Sadiku, Adetola" <Tola.Sadiku@?.com>
  • Date: Sat, 18 Jun 2016 14:48:53 +0000


Can someone please assist me with a working script or directions that will allow the QFTest sendEmail script to include an attachment.

I have done some research and tried to modify the jython script for the sendEmail_SMTPHost procedure but getting errors. It will be nice if there is an easier way to do this without needing to write code.


Please find attached my edited jython server script.



Thank you,

Tola Sadiku, MSC, CSM | Quality Assurance Analyst

Certified Scrum Master

AmeriPride Services

10801 Wayzata Boulevard, Minnetonka

Minnesota, MN 55305

O: 952-738-3232

F: 952-738-3158


People You Can Count On

Click here to submit a ticket!



"Good manners will open doors that the best education cannot” – Clarence Thomas 


import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
from os.path import basename
from email.mime.application import MIMEApplication

smtpHost = rc.lookup("smtpHost")
smtpUser = rc.lookup("smtpUser")
smtpPassword = rc.lookup("smtpPassword")
asHtml = rc.getBool("asHtml")

addstr = rc.lookup("to")
addarray= addstr.split(",")

addresses = []
for a in addarray:

msg = MIMEMultipart()
msg['From'] = rc.lookup("from")
msg['Subject'] = rc.lookup("subject")
msg['To'] = ",".join(addresses)

if asHtml:
    msg = MIMEText(rc.lookup("text"),"html")
    msg = MIMEText(rc.lookup("text"),"plain")    

part = MIMEBase('application', "octet-stream")
part.set_payload(open("text.txt", "rb").read())

part.add_header('Content-Disposition', 'attachment; filename="text.txt"')


# Send the message via SMTP server, but don't include the
# envelope header.

s = smtplib.SMTP(smtpHost)

if smtpUser != '': #only perform login, if user is specified
    s.login(smtpUser, smtpPassword)

s.sendmail(rc.lookup("from"), addresses, msg.as_string())