Page 1 of 1

V175 File Watcher Email Smtp

PostPosted: Wed Mar 15, 2017 7:15 pm
by 2can2
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

Re: V175 File Watcher Email Smtp

PostPosted: Wed Mar 15, 2017 7:33 pm
by Mike.Sheen
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

Re: V175 File Watcher Email Smtp

PostPosted: Thu May 25, 2017 2:15 pm
by 2can2
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.

Re: V175 File Watcher Email Smtp

PostPosted: Thu May 25, 2017 2:20 pm
by Scott.Pearce
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.

Re: V175 File Watcher Email Smtp

PostPosted: Thu May 25, 2017 6:47 pm
by Mike.Sheen
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 79805 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

Re: V175 File Watcher Email Smtp

PostPosted: Mon May 29, 2017 1:00 pm
by 2can2
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.

Re: V175 File Watcher Email Smtp

PostPosted: Mon May 29, 2017 1:30 pm
by Mike.Sheen
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

Re: V175 File Watcher Email Smtp

PostPosted: Fri Jun 02, 2017 4:38 pm
by 2can2
Ok. I will test this solution. Will it now become standard in a future release?

Re: V175 File Watcher Email Smtp  Topic is solved

PostPosted: Sun Jun 04, 2017 2:16 pm
by Mike.Sheen
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.