Exporting csv output to email

  • Last Post 08 February 2018
  • Topic Is Solved
PhinkTad posted this 14 August 2017


I have a workflow where I monitor a mailbox and process pdf files in it.
When someone emails a pdf attachment to the specified address, Abbyy should process the file and send csv output back to the sender.

I was able to get the export script to send email..just need help getting the sender's email address, so that I can send the processed output file back to the same sender.
Any examples, scripts would be very helpful.


Thank you!

Order By: Standard | Newest | Votes
Ekaterina posted this 16 August 2017


When you import images from an e-mail folder using the MAPI or POP3 server protocols, information about the message will be automatically added to the registration parameters of the batch you are creating (see the Registration Parameters article in the Developers Help).

  • Liked by
  • PhinkTad
Aida posted this 06 February 2018

Hello PhinkTad,

I am interested in implementing the same functionality, would you mind to share the script with me and more details about how you managed to make this work?

Thank you very much in advance

PhinkTad posted this 06 February 2018

Hi Aida,

You can follow the notes from the link here to create a custom export.


I wouldn't be able to share the entire project, but the idea is like this.. you have to add a custom export option in the document definition. Add some scripts there to get properties such as the email sender etc in here.

On the workflow, add a custom stage and script your .net code to send email. I saved the document to local drive and then had the script call the file and use it to send as an attachment.
Use documentid and batchid properties to customize the output email.
Let me know if you're stuck anywhere.

  • Liked by
  • Aida
  • Melisa Uy
Aida posted this 07 February 2018

Hi PhinkTad,

Thank you very much for your reply.

I am a little new to ABBYY, so let me recap. If I understand you well, in my document definition properties, I can acess the workflow tab, when setting the same in advanced I can add a new stage to the process that will send the email. I can access this stage from the Stage Toools tab and relate the same to an event (I am not sure which Event I should relate it to), and then add my script to send the mail. Is this correct.

On the other hand, could you please share with me only the scripting part for getting the email sender?

Thank you very much again for your help and excuse my inexpenrience in this matter.


PhinkTad posted this 08 February 2018

Hi Aida,

In the document definition properties, under export destinations, add an export of type 'Custom export(script)' and enter the following.



    string exportPath = @"C:\ExportFC\";

    IExportImageSavingOptions options = FCTools.NewImageSavingOptions();

    ExternalExports.Export export = new ExternalExports.Export();


   int bid = Document.Batch.Id;


    export.exportToTxt(bid, Document,  exportPath);




catch (System.Exception e)


    Processing.ReportError("Error: " + e.Message);



On the project setup station, click project->properties-> workflow tab.
Add a new stage of type user type just after the export stage.
Create a script of type batch processing and paste the following..

using System;

using System.Net;

using System.Net.Mail;

using System.IO;

using System.Collections.Generic;


string senderEmail = Batch.Properties.Get("fc_Predefined:EmailSender"); 

string senderEmailAbs = senderEmail.Split('<','>')[1];

int bid = Batch.Id;

string path = @"C:\ExportFC\"+bid.ToString();

string attFile = path+@"\"+"Batch"+bid+@".csv";





string sourceFolder = path;

            string destinationFile = attFile;


            // Specify wildcard search to match CSV files that will be combined

            string[] filePaths = Directory.GetFiles(sourceFolder, @"*.csv");

            StreamWriter fileDest = new StreamWriter(destinationFile, true);


            int i;

            for (i = 0; i < filePaths.Length; i++)


                string file = filePaths[i];


                string[] lines = File.ReadAllLines(file);

                List<String> llines = new List<string>();

                foreach (string ln in lines)





                if (i > 0)


                   // lines = lines.Skip(1).ToArray(); // Skip header row for all but first file

                   // lines = lines.Skip(1).ToArray();





                foreach (string line in llines)











MailMessage mail = new MailMessage();

            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("sender@gmail.com");


            mail.Subject = "CSV output for Batch#- " + bid;

            mail.Body = "Please check the attachment!";


            System.Net.Mail.Attachment attachment;

            attachment = new System.Net.Mail.Attachment(attFile);



            SmtpServer.Port = 587;

            SmtpServer.Credentials = new System.Net.NetworkCredential("receiver@gmail.com", "enterpwd");

            SmtpServer.EnableSsl = true;




You would need to download the customexport zip file from https://knowledgebase.abbyy.com/article/1266
and update your project with the ExternalExport.dll. I added it in the document definition properties->.net references-> add.
You need to create an import profile of type email and enter the servername and port and under settings, the email login and password, whether or not to use SSL.

That's pretty much it.
Hope you find it useful!


  • Liked by
  • Aida
  • Melisa Uy