Hi Community,
is there a way to send an email when a document required data verification in FlexiCapture 12? I tried including the following script in "After document state changed" event. But no file is created (under C:\test.txt). Any help?
Regards,
Michael
using System;
using System.IO;using(var writer = new StreamWriter("C:\\test.txt", true)) {
for(var i=0;i<8;i++) {
writer.Write(DateTime.Now);
writer.Write(i);
writer.Write(ChangedStates.Has(i));
writer.WriteLine();
}
}
Comments
19 comments
Hi Michael,
This event handler should fire during the document export. Please use additional workflow stage for this requirement. Add this stage after Recognition stage (Base settings: Automatic). Add Group of rules for entry condition: "Has rule errors", "Has assembly errors" and Characters to verify > 0, or just add Has rule errors, it is up to your requirement. In script of workflow stage add your code for sending an email and that should be it.
Best regards,
Vladimir
Hi Vladimir,
Thank you for your response. I tried adding the script as you said (activating, that it is always executed) and added the following code to send the mail.
Unfortunately, the code is never executed. Same example does also not work when using the code in my first post. I placed the Script step between recognition and verification. Am I missing something?
Regards,
Michael
Hi Michael,
Here is the code that works on my machine:
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
try
{
SmtpClient smtp = new SmtpClient("mail.someemailserver.com");
smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("sender.email@email.com", "password");
smtp.Credentials = basicAuthenticationInfo;
MailAddress emailFrom = new MailAddress("sender.email@email.com", "Sender Name");
MailAddress emailTo = new MailAddress("recipient.email@email.com", "Recipient Email");
MailMessage email = new System.Net.Mail.MailMessage(emailFrom, emailTo);
email.Subject = "Document for Verification";
email.SubjectEncoding = System.Text.Encoding.UTF8;
email.Body = "Document Id:<b>" + Document.Id + ".</b>";
email.BodyEncoding = System.Text.Encoding.UTF8;
email.IsBodyHtml = true;
smtp.Send(email);
}
catch (Exception ex)
{
FCTools.ShowMessage(ex.ToString());
}
Hi Vladimir,
thanks again for your response. Codewise I do not see a significant difference in your code rather then in mine. Would made it finally work was that I had to specify the workflow in the Batch Types and not in the Project Properties (I am processing files from a Hot Folder).
What I also like is the error handling you put in. I wasn't aware of the FCTools namespace.
Regards,
Michael
Hi Michael,
You're welcome. I prefer to use Batch Types, regardless of project type or size of project. Good to know that you solve the issue now.
Best regards,
Vladimir
Hi Michael,
Regarding your original question about the test.txt file in the root directory on C:
Check if you have file creation privileges in that location.
Try saving a file from Notepad to that location.
On my Win 10 system, I can create folders, but NOT files in C:
I always put my debug files in C:\users\.....
M.
Hi M.,
Thanks for your post. I checked again and validated the privileges. The error was caused by the wrong workflow executed and not the file system privileges. But generally I agree that files should be put in subfolders with the privileges set correctly.
Regards,
Michael
Hi Vladimir,
Now the next question arises. If I want to send an email in case of an exception ... what do I have to do then? I tried adding a processing step after the exception but it does not get fired.
Regards,
Michael
Hi Vladimir
Can you point me in the direction how to query the exception queue outside of ABBYY (PowerShell, C#, VBScript)?
Regards,
Michael
Hi mates,
I am interested in the question, I am going to follow the thread and try to move forward and help.
Regards.
Hi mates,
I have followed your instructions, but the action of sending the e-mail does not trigger. The only difference is your version, i`m with FC11, but i do not think it`s related. I used the Vladimir code. In the event handler i used the trigger: request field verification.
Regards.
Hi all,
I think it is better to start a new topic regarding the exceptions. While creating the topic, I found the following link http://www.capturedocs.com/thread/4728-failed-import-notification/ which explains basically, that exception files should be moved to a dedicated folder which is then observed by a service or event handler. I solved this by using PRTG Monitor.
Regards,
Michael
Hello,
Workflow settings that are customized on the Project > Project Properties > Workflow tab are applied only when the <Default> batch type is processed. If you are using various batchtypes, they have their own workflows that should be customized separately for each used batch type.
Hi Ekaterina,
I have a custom batch, but the code of the email i have it configured in even so Project > Batch types > my Batch > events > field verification request. It does not work for me, there is an imagen in the previus commnetary where you can see which one is on and the trigger does not work.
Thanks.
hi
Now the mail is sent !!! but i have to select the document and send it to verify, at that point the mail is sent, my interest is to send it before that, that is to say to notify the user that has the task of verification or revision of some document.
Regards
Hi Antal,
In case like this, you shouldn't use Event Handlers, you have to create new stage in Workflow for your batch type. Go to:
Project -> Batch Types -> my Batch -> Workflow -> Add Stage. Click on Automatic and click button OK. Add name to your stage, make entry conditions if needed. In Script tab, set type to Document Processing and add your code to the script. That would be it.
Best regards,
Vladimir
Hi,
I have used below code to send email before custom stage script but it did not work, Please suggest
Error
7/31/2019 3:17:24 PM : at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Main.Execute(IBatch Batch, IDocuments Documents, IProcessingCallback Processing)
Code
using System;
using System.Xml;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.IO;
string logFilePath = @"D:\log\";
string filepath;
if (!Directory.Exists(logFilePath))
{
Directory.CreateDirectory(logFilePath);
}
filepath = logFilePath + "ServiceLog.txt";
if (!File.Exists(filepath))
{
File.Create(filepath);
}
try
{
using (StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(DateTime.Now.ToString() + " : " + "Method statred");
}
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Timeout = 300000;
smtp.Port = 465;
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("user@gmail.com", "password");
smtp.Credentials = basicAuthenticationInfo;
MailAddress emailFrom = new MailAddress("user@gmail.com", "sender");
MailAddress emailTo = new MailAddress("reciver@live.com", "Recipient Email");
MailMessage email = new System.Net.Mail.MailMessage(emailFrom, emailTo);
email.Subject = "Document for Verification";
email.SubjectEncoding = System.Text.Encoding.UTF8;
email.Body = "Document Id:<b>" + "Hello" + ".</b>";
email.BodyEncoding = System.Text.Encoding.UTF8;
email.IsBodyHtml = true;
using (StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(DateTime.Now.ToString() + " : " + "Started Send");
}
smtp.Send(email);
using (StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(DateTime.Now.ToString() + " : " + "End Send");
}
}
catch (Exception ex)
{
using (StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(DateTime.Now.ToString() + " : " + "Exception");
sw.WriteLine(DateTime.Now.ToString() + " : " + ex.Message);
sw.WriteLine(DateTime.Now.ToString() + " : " + ex.StackTrace);
}
}
Hello,
We don't provide code samples or fix the .net errors in the scope of this forum, for this kind of assistance please contact the professional service of your regional support
Please sign in to leave a comment.