Kofax TotalAgility to send Email
using System;
using System.Net;
using System.Net.Mail;
using Agility.Server.Scripting.ScriptAssembly;
using TotalAgility.Sdk;
using Agility.Sdk.Model.Capture;
using System.IO;
using System.Net.Mime;
//using System.Collections.Specialized;
using System.Collections;
using System.Collections.Generic;
namespace MyNamespace
{
public class Class1
{
CaptureDocumentService cds = new CaptureDocumentService();
public Class1()
{
}
[StartMethodAttribute()]
public void Method1(ScriptParameters sp)
{
var folderId = (string)sp.InputVariables["
KeyFolder
Process variable
"];
var sessionId = (string)sp.InputVariables["
SPP_SYSTEM_SESSION_ID
Server variable
"];
var SMTPlogin = (string)sp.InputVariables["
SMTP User
Server variable
"];
var SMTPpassword = (string)sp.InputVariables["
SMTP Password
Server variable
"];
var smtpClient = new SmtpClient("127.0.0.1")
{
Port = 2525,
Credentials = new NetworkCredential(SMTPlogin, SMTPpassword),
EnableSsl = false,
};
var mailMessage = new MailMessage
{
From = new MailAddress((string)sp.InputVariables["
EmailFrom
Process variable
"]),
Subject = "KTA " + (string)sp.InputVariables["
InEmail_SRC
Process variable
"] + " " + (string)sp.InputVariables["
Out_No
Process variable
"] + " " + "|" + " " + (string)sp.InputVariables["
DocType_CURR
Process variable
"],
Body = "PDF KTA Sending Test Document into Email. \n\nRef: " + (string)sp.InputVariables["
Out_Ref
Process variable
"]
};
mailMessage.To.Add((string)sp.InputVariables["
EmailTo
Process variable
"]);
string idMerge = (string)sp.InputVariables["
KeyFolderMergeID
Process variable
"];
Folder folder = cds.GetFolder(sessionId, null, folderId);
// Agility.Sdk.Model.Server.StringCollection collDocId = new Agility.Sdk.Model.Server.StringCollection();
//List<string> listDocId = new List<string>();
//Console.WriteLine( "Initial contents of the StringCollection:" );
foreach (var doc in folder.Documents)
{
Stream docStream = cds.GetDocumentFile(sessionId, null, doc.Id, "pdf");
// "application/pdf"
// MediaTypeNames.Application.Pdf
var attachment = new Attachment(docStream, (string)sp.InputVariables["
DocType_CURR
Process variable
"] + "_" + doc.Id + ".pdf", "application/pdf");
mailMessage.Attachments.Add(attachment);
// collDocId.Add( doc.Id );
// listDocId.Add(doc.Id );
}
//string[] arrStr = listDocId.ToArray();
/*
if(listDocId.Count>0) {
idMerge = arrStr[0];
sp.OutputVariables["
KeyFolderMergeID
Process variable
"] = idMerge;
//collDocId.AddRange(arrStr);
//sp.OutputVariables["
tempMSG
Process variable
"] = "Merge DocId: " + string.Join(",", collDocId);
}else
{
//Console.WriteLine("NoData");
sp.OutputVariables["
KeyFolderMergeID
Process variable
"] = "";
}
//
Stream docMStream = cds.GetDocumentFile(sessionId, null, idMerge , "pdf");
//cds.MergeDocuments(sessionId , collDocId );
var attachmentM = new Attachment(docMStream , (string)sp.InputVariables["
DocType_CURR
Process variable
"] + "_" + idMerge + "-Merge.pdf", "application/pdf");
mailMessage.Attachments.Add(attachmentM);
*/
smtpClient.Send(mailMessage);
}
}
}
C# Sample
using System;
using System.Net;
using System.Net.Mail;
using Agility.Server.Scripting.ScriptAssembly;
using TotalAgility.Sdk;
using Agility.Sdk.Model.Capture;
using System.IO;
using System.Net.Mime;
//using System.Collections.Specialized;
using System.Collections;
using System.Collections.Generic;
namespace MyNamespace
{
public class Class1
{
CaptureDocumentService cds = new CaptureDocumentService();
public Class1()
{
}
[StartMethodAttribute()]
public void Method1(ScriptParameters sp)
{
var folderId = (string)sp.InputVariables["
KeyFolderShipment
Process variable
"];
var sessionId = (string)sp.InputVariables["
SPP_SYSTEM_SESSION_ID
Server variable
"];
var SMTPlogin = (string)sp.InputVariables["
SMTP User
Server variable
"];
var SMTPpassword = (string)sp.InputVariables["
SMTP Password
Server variable
"];
var smtpClient = new SmtpClient("127.0.0.1")
{
Port = 2525,
Credentials = new NetworkCredential(SMTPlogin, SMTPpassword),
EnableSsl = false,
};
var mailMessage = new MailMessage
{
From = new MailAddress((string)sp.InputVariables["
EmailFrom
Process variable
"]),
Subject = "KTA " + (string)sp.InputVariables["
InEmail_SRC
Process variable
"] + " " + (string)sp.InputVariables["
Out_ShipNo
Process variable
"] + " " + "|" + " " + (string)sp.InputVariables["
DocType_CURR
Process variable
"],
Body = "PDF IMP Sending Test Document into Email. \n\nDN: " + (string)sp.InputVariables["
Out_DN
Process variable
"]
};
mailMessage.To.Add((string)sp.InputVariables["
EmailTo
Process variable
"]);
string idMerge = (string)sp.InputVariables["
KeyFolderMergeID
Process variable
"];
Folder folder = cds.GetFolder(sessionId, null, folderId);
// Agility.Sdk.Model.Server.StringCollection collDocId = new Agility.Sdk.Model.Server.StringCollection();
//List<string> listDocId = new List<string>();
//Console.WriteLine( "Initial contents of the StringCollection:" );
foreach (var doc in folder.Documents)
{
Stream docStream = cds.GetDocumentFile(sessionId, null, doc.Id, "pdf");
// "application/pdf"
// MediaTypeNames.Application.Pdf
var attachment = new Attachment(docStream, (string)sp.InputVariables["
DocType_CURR
Process variable
"] + "_" + doc.Id + ".pdf", "application/pdf");
mailMessage.Attachments.Add(attachment);
// collDocId.Add( doc.Id );
// listDocId.Add(doc.Id );
}
//string[] arrStr = listDocId.ToArray();
/*
if(listDocId.Count>0) {
idMerge = arrStr[0];
sp.OutputVariables["
KeyFolderMergeID
Process variable
"] = idMerge;
//collDocId.AddRange(arrStr);
//sp.OutputVariables["
tempMSG
Process variable
"] = "Merge DocId: " + string.Join(",", collDocId);
}else
{
//Console.WriteLine("NoData");
sp.OutputVariables["
KeyFolderMergeID
Process variable
"] = "";
}
//
Stream docMStream = cds.GetDocumentFile(sessionId, null, idMerge , "pdf");
//cds.MergeDocuments(sessionId , collDocId );
var attachmentM = new Attachment(docMStream , (string)sp.InputVariables["
DocType_CURR
Process variable
"] + "_" + idMerge + "-Merge.pdf", "application/pdf");
mailMessage.Attachments.Add(attachmentM);
*/
smtpClient.Send(mailMessage);
}
}
}