Logo QF-Test

Finding valuable answers
in the Mailing List Archive.

 

Free Trial  Download  Buy

Thomas Max, QF-Test training and support

Use the full-text search on our web site to find helpful tips on the mailing list.

Thomas Max, 
Sr. Software Engineer & Trainer, QFS

2017 up to now  | 2016 | 2015 | 2014 | 2013 | 2012 | 2011 | 2010 | 2009 | 2008 | 2007

(older archive entries before 2007 are not shown here, but included in the onsite-search)

Mailing List - Entries of 2016


[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

Hello,

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

tola.sadiku@?.com

www.ameripride.com

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:
    addresses.append(a.strip())

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

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

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

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

msg.attach(part)

# 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())
s.quit()

Videos Downloads Documentation Buy Free Trial