Skip to main content
Question

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

  • November 23, 2018
  • 6 replies
  • 34 views

Forum|alt.badge.img

 

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

takashi
Celebrity
  • 7842 replies
  • November 23, 2018

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()

Forum|alt.badge.img
  • Author
  • 55 replies
  • November 24, 2018

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?

takashi
Celebrity
  • 7842 replies
  • November 25, 2018

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.


david_r
Celebrity
  • 8391 replies
  • November 26, 2018

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.


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2937 replies
  • November 26, 2018

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.


Forum|alt.badge.img
  • Author
  • 55 replies
  • November 30, 2018

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