This is an example on how to use the Manage Code C# Shape in the Advance stencil to send email with attachment.
Insert below code snippet in the code editor of the Manager Code C# Shape in Envision. You may obtain the example of vsd file here.
In this example, the attachment file is located under the virtual directory of AgilePoint Server, which AgilePoint Server has no problem to access the file. If you want to use other location, make use AgilePoint Server Application Pool has enough privilege to access the location of your attachments.
using System;
using System.Collections;
using System.Data;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;
using Ascentn.Workflow.Base;
namespace ManagedCode
{
public class CSharpCodeSnippet
{
// Invoke method is this class's entry point
public void Invoke(
WFProcessInstance pi,
WFAutomaticWorkItem w,
IWFAPI api,
NameValue[] parameters)
{
string emailAddress = WFSystem.SysAdmEMailAddress;
string attachment = WFSystem.HomeDirectory + "\\License.en-US.RTF";
IWFActivityInstance ai = api.GetActivityInst(w.ActivityInstID);
api.SendMail(
pi,
ai,
emailAddress,
null,
string.Format("Request for Approval - {0}", pi.ProcInstName),
"You are assigned with this task, please review and approve within two days.",
attachment);
}
}
}
Debugging:
Make use of AgilePoint Server log located at [AgilePointVirtualDirectory]\AgilePointServer\log for debugging. For example, if your attachment file is missing, you can find error log below in AgilePoint Server log.
7/1/2009 09:49:36 >>> Send Mail, attaching file does not exists, file='C:\AgilePoint\AgilePointServer\License.RTF', ID='2AD5BB44AE5B42DF94F6492BF744C2A2'
No comments:
Post a Comment