V175 File Watcher Email Smtp  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

V175 File Watcher Email Smtp

Postby 2can2 » Wed Mar 15, 2017 7:15 pm

Hi, I just wanted to check if there would be no issue with me enabling the Smtp Email code in the file watcher for the duration of sending the email and then disabling it.
The clients use Outlook for emailing So, Po's etc daily but I need to be able to email any errors out of File watcher and Smtp seems the only option.
What I want to do is :

email.SystemSettings.UseOutlookForEmail = False ' Cannot use outlook from within a Windows Service - make sure your other system settings like SMTP server are configured.
email.CreateNew()
email.EmailTo = "[email protected]"
email.EmailSubject = "test email"
email.EmailBody = String.Format("Document '{0}' failed to import - error message is '{1}'", pendingFileNameAndPath, ex.Message)
email.Save()
'' THEN add
email.SystemSettings.UseOutlookForEmail = TRUe.

Will this be ok? Thanks
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: V175 File Watcher Email Smtp

Postby Mike.Sheen » Wed Mar 15, 2017 7:33 pm

Unfortunately your solution won't work. But the good news is there is a solution!

The setting UseOutlookForEmail is deprecated, and instead we rely on whatever email plugins are enabled to send emails. If you enable multiple plugins for emailing, then that will result in multiple emails being sent and in the case of sending from within a Windows service, sending via outlook or Office365 will likely result in an error.

The way around this is as follows:

  • Make sure the Windows service logs onto Jiwa using a specific user name
  • Copy both the standard Outlook email plugin and the SMTP plugin, enable each and save them
  • Disable the standard Outlook email plugin and the SMTP plugin
  • Modify the code in each plugin to only attempt to email if the username matches or does not match the username the service uses. So, in the SMTP email plugin, wrap that in a check for username == usernameusedbywindowsservice, and in the outlook plugin, wrap that in a check for username != usernameusedbywindowsservice
  • Save the plugins, exit Jiwa and test.

If you can't work it out within a short time frame, let me know here and I'll do up some plugins, test and post them here.

Mike

EDIT: We should probably provide a way to specify per Jiwa user which plugin to use to send emails - logged as DEV-5857
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: V175 File Watcher Email Smtp

Postby 2can2 » Thu May 25, 2017 2:15 pm

Hi, I am not sure how to go about the steps you have outlined. How do I ensure the windows service logs into Jiwa with a specific name?
Can you do up some plugins as suggested, that would make it far easier, thanks.
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: V175 File Watcher Email Smtp

Postby Scott.Pearce » Thu May 25, 2017 2:20 pm

2can2 wrote:How do I ensure the windows service logs into Jiwa with a specific name?


The Jiwa Plugin Scheduler Service reads it's configuration upon startup from the file "JiwaPluginSchedulerService.exe.config" (which resides in the Jiwa installation folder). It is in that file that the username and password to use to log in to Jiwa is defined.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: V175 File Watcher Email Smtp

Postby Mike.Sheen » Thu May 25, 2017 6:47 pm

Hi Doug,

Attached is a plugin which adds a custom field to the Staff Maintenance form, allowing an Email provider to be set per staff member.

Import the plugin, save and then DISABLE any of our other email plugins.

Then in system configuration, set the values for the SMTP and / or Office 365 API Key:
MultipleEmailProviders_SystemSettings.PNG


And then per staff member set the "EmailProvider" on the Custom tab of staff maintenance:
MultipleEmailProviders_StaffMaint.PNG
MultipleEmailProviders_StaffMaint.PNG (54.81 KiB) Viewed 5569 times


When emails are sent, the staff member custom field "EmailProvider" is examined, and the appropriate provider is invoked. Unfortunately I couldn't leverage the existing plugins to act as providers, so I copy-pasted their code into this new plugin - but I made it so it's easy to extend and add new providers should there ever be a need.

Mike
Attachments
Plugin Multiple Email Providers.xml
(64.25 KiB) Downloaded 111 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: V175 File Watcher Email Smtp

Postby 2can2 » Mon May 29, 2017 1:00 pm

Thanks for all the work Mike. Looks like a great solution, I guess it means copying the relevant code into all the custom email plugins that I am using.

The file watcher plugin states ''email.SystemSettings.UseOutlookForEmail = False ' Cannot use outlook from within a Windows Service - make sure your other system settings like SMTP server are configured.'
Your previous response implied that this was no longer the case? if that is correct then the simplest solution in this case would be to send the email via outlook and the clients problem is simply solved.
It is only the file watcher at this point that needs to be send an email using SMTP.
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: V175 File Watcher Email Smtp

Postby Mike.Sheen » Mon May 29, 2017 1:30 pm

2can2 wrote:The file watcher plugin states ''email.SystemSettings.UseOutlookForEmail = False ' Cannot use outlook from within a Windows Service - make sure your other system settings like SMTP server are configured.'
Your previous response implied that this was no longer the case? if that is correct then the simplest solution in this case would be to send the email via outlook and the clients problem is simply solved.
It is only the file watcher at this point that needs to be send an email using SMTP.


That comment in the standard file watcher plugin is now irrelevant and incorrect, as that system setting was deprecated when we introduced plugins to perform the emailing. We need to update the plugin to remove that comment.

Services still cannot send email using Outlook - they need another mechanism - the SMTP method would be ideal - so the plugin provided in my previous post would be ideal - as long as the Plugin Scheduler service is configured to use a specific user, and that user is configured to send via SMTP.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: V175 File Watcher Email Smtp

Postby 2can2 » Fri Jun 02, 2017 4:38 pm

Ok. I will test this solution. Will it now become standard in a future release?
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: V175 File Watcher Email Smtp  Topic is solved

Postby Mike.Sheen » Sun Jun 04, 2017 2:16 pm

2can2 wrote:Ok. I will test this solution. Will it now become standard in a future release?


Yes, DEV-5857 has been logged to make this standard functionality, as I mentioned previously.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 16 guests