This is a sample procedure that has 2 parts:
1) An admin form that allows you to test emailing functionality visually.
2) Server side logic that controls all the emailing for a process based on action name/stage name you pass. All you have to do is call the script from an action/stage event.
Also included stored procedure to creates line item for emails in a group. Some of the code used is below.
Edit for code cleanup
Stored Procedure for group email
CREATE PROCEDURE [dbo].[sp_BuildGroupEmails]
@EmailGroup nvarchar(500)
AS
BEGIN
Declare @Emails nvarchar(2000)
SELECT @Emails = coalesce(@Emails + '; ', '') + eEMailAddress FROM eUser WHERE eUserName IN
( SELECT eUserName FROM eAssignment WHERE eRoleName = @EmailGroup)
SELECT @Emails
END
Call email script from Action/Stage
//Calls code to manage email and adds to notes
ProcessContext.ActionNote = EmailScripts.SendEmails(ProcessContext.ActionName, ProcessContext.FolderId )
Server Side Call to Send Email
The only thing you really need to do here is set the default values and the Case logic info
[Promote(PromotionTargets.ExpressionBuilder)]
[Category("Communication")]
[Alias("Email Functions")]
[Description("Send Email")]
public static Metastorm.Runtime.Types.Text SendEmails
(
[Alias("Action Name")] [Description("the name of the stage/action")] Text action,
[Alias("FolderID")] [Description("processcontext folderid")] Text folderid
)
{
//set defaul variables
string sendto = "<target user email>";
string sendcc = "";
string sendbcc = "";
string attachment = "";
string sendfrom = "<metastorm server email>";
string subject = "Test Subject";
string weblink = "<a href='<metastorm server url>'>Go to Metastorm System</a>";
string folderlink = "<a href='<metstorm server url>/metastorm/eFolder.aspx?FolderID=" +
folderid + "&Client=External'>Go to Folder</a>";
//build email body
string messageheader = "";
string message = "<pre>" +
"<br> <b><u>Access</u></b>" +
"<br> <b>Web Link:</b> " + weblink +
"<br> <b>Folder Link:</b> " + folderlink +
"<div align='center'><b><i>NOTE: This email was generated by Metastorm. Please do not reply.</i></b></div>";
switch (action.ToString().ToLower())
{
case "createtestemail":
messageheader = "Created a test email";
//sendto = "";
break;
case "entry":
messageheader = "New request has been submitted";
//sendto = "";
break;
case "archive":
messageheader = "Request sas been archived";
//sendto = "";
break;
default:
messageheader = "Metastorm notification";
//sendto = "";
break;
}
message = messageheader + "<br><br>" + message;
return "Email Notification Sent To: " + sendto + " " +
Mstm.SendEmail(sendto, sendcc, sendbcc, subject, message, attachment, sendfrom).ToString();
}
Well it works but always room for improvements. Enjoy.