Question

How to do email filtering inside shutdown python script and also exporting the result in sql server DB table?

  • 23 November 2018
  • 6 replies
  • 1 view

Badge

 

Dear everyone, I have an shutdown python scripts which basically sends email to admin after one datadownload has been succeed or failed. My existing py script is as follows:

 

I now want to impose one "if" condition before email generate, if my user name is "A" and email is "A@nnn.com" then email will not generate.. I have ended my script as follows but it did not work, FME server shows me error.

 

if nutzer != 'A' AND user_mail != 'A@nnn.com':

 

smtpserver = smtplib.SMTP(smtpServerAdress,smtpPort)

 

smtpserver.ehlo()

 

smtpserver.starttls()

 

smtpserver.ehlo

 

smtpserver.sendmail(emailFrom, emailTo, msg.as_string())

 

smtpserver.close()

 

 

...............

 

Did I have done some mistakes?

 

 

And another issue is, I want to also store the result inside sql server DB , how i can write the right script before'send mail?

 

Thanks

Muqit


6 replies

Userlevel 2
Badge +17

The "and" operator should be lower case, and appropriate indentations are required for the code block within the if statement, as in:

if nutzer != 'A' and user_mail != 'A@nnn.com':
    smtpserver = smtplib.SMTP(smtpServerAdress,smtpPort)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.sendmail(emailFrom, emailTo, msg.as_string())
    smtpserver.close()
Badge

The "and" operator should be lower case, and appropriate indentations are required for the code block within the if statement, as in:

if nutzer != 'A' and user_mail != 'A@nnn.com':
    smtpserver = smtplib.SMTP(smtpServerAdress,smtpPort)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.sendmail(emailFrom, emailTo, msg.as_string())
    smtpserver.close()

Thanks a lot. 

Cann you please also tell me if I could transfer this results into one sql server DB table?
Userlevel 2
Badge +17

Thanks a lot.

Cann you please also tell me if I could transfer this results into one sql server DB table?

I have no experience having connected to an MS SQL Server database with Python script, so cannot help you. It would be better to post a new question specific to the matter.

Userlevel 4

Rather than using the shutdown script for this, I would really recommend replacing the workspace writers with FeatureWriters and chain an Emailer and a SQLServer writer to the Summary port.

This way you'll have no Python code to write or maintain.

Userlevel 6
Badge +31

Rather than using the shutdown script for this, I would really recommend replacing the workspace writers with FeatureWriters and chain an Emailer and a SQLServer writer to the Summary port.

This way you'll have no Python code to write or maintain.

This. We use the Emailer transformer a lot in our Server Workspaces.

Badge

Rather than using the shutdown script for this, I would really recommend replacing the workspace writers with FeatureWriters and chain an Emailer and a SQLServer writer to the Summary port.

This way you'll have no Python code to write or maintain.

Thanks david_r for your suggestions. I have successfully connected custom python and third party packages with FME workspace and also fme server and getting all the required results in sql server table.

Kind regards

Muqit

Reply