Jump to content
Server Maintenance This Week. ×

"Universal" email script to email alerts from various files/scripts.


Recommended Posts

I have several scripts throughout my solution(s) that incorporate a Send Mail (Send via SMTP Server) step.  The email credentials, subject, recipient, and message body are individually added in each individual script.  We recently changed email providers, and are now using O365.  As such, I've discovered two issues...(1) it's a pain to go through each script and update the SMTP settings for the new provider.  (2) MS is more finicky than my previous provider (as it relates to security), so I have to be careful with application specific passwords, etc.

I have a related file named dBase Common, which is accessible from my various tables/files, so I started to create a central email script, which has a single set of SMTP credentials, but uses variables to customize the content for "To:", "From:", "Subject:", 'Message".  So far, I've not been successful making the script work, and I believe it has to do with the movement of variable data from one file to the next.  Below is an example of my script steps:

---

Origination Script:

Set Variable [ $$SendMailTo ; Value: "[email protected]" ]

Set Variable [ $$SendMailSubject ; Value: "MISC Product Database has changed for " & MISC PRODUCT LIST::MISC_ID_Revision_NEW ]

Set Variable [ $$SendMailMessage ; Value: MISC PRODUCT LIST::MISC_ID_Revision_NEW & ¶ & GetNthRecord ( REVISION LOG_PRD::Revision_date ; 1 )&" - "& GetNthRecord ( REVISION LOG_PRD::Revision_description ; 1 )&" - "& GetNthRecord ( REVISION LOG_PRD::Revision_approval ; 1 ) ]

Perform Script [ Specified: From list ; “Email Alert” from file: “dBase Common” ; Parameter:    ]

##Below are the steps from the "Email Alert" script from the different file:

Send Mail [ Send via SMTP Server ; No dialog ; To: $$SendMailTo ; CC: $$SendMailCC ; BCC: $$SendMailBCC ; Subject: $$SendMailSubject ; Message: $$SendMailMessage ]

---

I've confirmed that the Email Alert script works (via test copy), if I manually enter a recipient, which tells me that the variable data "handoff" is the problem.  Should I be using a Script Parameter instead?  Please advise?

 

Thanks,

Bill

 

 

Link to comment
Share on other sites

The scope of variables defined in the source file is limited to that file and does not extend to the target file that performs the actual script.

Besides, it's not good practice to use global variables when they will be no longer required after the script has run.

The proper solution here, IMHO, is to use a script parameter. And since you need to pass several discrete values within this parameter, AND some of these values may contain carriage returns, it would be best to wrap these values in a JSON object and let the receiving script extract them from there.

 

Link to comment
Share on other sites

Although, since only one of the three values can contain carriage returns, you could just send them all in a list, then extract the address as GetValue ( Get ( ScriptParameter ) ; 1 ), the subject as GetValue ( Get ( ScriptParameter ) ; 2 ) and the message as  RightValues ( Get ( ScriptParameter ) ; ValueCount ( Get ( ScriptParameter ) ) - 2 ).

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.