I am trying to set my workspace to send an email using a shutdown python script.
For doing so, I used the following Python script found on one of the Safe articles:
import smtplib, fmeobjects
to = FME_MacroValues['EmailTo']
gmail_user = FME_MacroValues['GmailUser']
gmail_pwd = FME_MacroValues['Password']
Subject = FME_MacroValues['SuccessSubject']
FailSubject = FME_MacroValues['FailSubject']
Emailfrom = FME_MacroValues['EmailFrom']
Jobs = FME_MacroValues['JOBID']
FeaturesWritten = str(FME_FeaturesWritten)
status = FME_Status
if status == 0:
Subject = FailSubject
Message = 'Workspace Failed'
else:
Message = 'Workspace Successful. Resulting *.dwg Can Be Located At C:\\Temp'
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\\n' + 'From: ' + Emailfrom + '\\n' + 'Subject:' + Subject +'\\n'
print header
msg = header + '\\n' + Message + '\\n\\n'
smtpserver.sendmail(gmail_user, to, msg)
print 'done!'
smtpserver.close()
This code works fine, but what I need to do is set the email destination ("to" variable) to an attribute called _Email_submitter.
But when I try to do so, the translation fails.
I setting the variable like this:
feature.getAttribute("_Email_submitter") = email
to = email
This is the only part in the entire code that is changed, but for some reason its causing the translation to fail.
I am not sure with I am having a problem retriving the attribute value (the list have only one value) or if is not possible to set an attribute value as the email destination.
Thanks,
Gabriel