Email notifications

  • 8 November 2005
  • 6 replies
  • 3 views

Badge +3
I have created a function to resolve my own groups for AD. This function updates an xml field called email with a comma delimited list of email names.

when the email is sent, the recipient gets multiple copies of the same email. Can you tell me if there is something wrong with this code?

thanks,

int AppIndex = Convert.ToInt32(K2.ProcessInstance.DataFields["CurrentStepIndex"].Value);

try
{
//Get the current step and count the approvers
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(K2.ProcessInstance.XmlFields[0].Value);
System.Xml.XmlNodeList CurrentStepApprovers = xmlDoc.SelectNodes("Workflow/Steps/Step[position()=" + AppIndex + "]/Approvers/Approver");

if (CurrentStepApprovers != null)
{
strFrom = SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(K2.ProcessInstance.XmlFields["SWFRequest"].Value,"Workflow/Steps/Step[position()=" + AppIndex + "]/Notifications/Start/From");
strSubject = SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(K2.ProcessInstance.XmlFields["SWFRequest"].Value,"Workflow/Steps/Step[position()=" + AppIndex + "]/Notifications/Start/Subject");
strBody = SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(K2.ProcessInstance.XmlFields["SWFRequest"].Value,"Workflow/Steps/Step[position()=" + AppIndex + "]/Notifications/Start/Body");

//get all of the approver names for this step and add to the email TO field.
int noApprovers = CurrentStepApprovers.Count;
if (noApprovers > 0)
{
for (int i = 1; i<=noApprovers; i++)
{
strEmail = "";
strEmail += SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(K2.ProcessInstance.XmlFields["SWFRequest"].Value,"Workflow/Steps/Step[position()=" + AppIndex + "]/Approvers/Approver[position()=" + i + "]/Email");
if((strEmail==null)||(strEmail.ToString().Trim().Length == 0))
{
throw new System.Exception("No Email Address was supplied, please rectify and try again.");
}
else
{

objMsg.From = strFrom.ToString();
objMsg.Subject = strSubject.ToString();
objMsg.Body = strBody.ToString();
objMsg.To = strEmail.ToString();
objMsg.Subject = strSubject.ToString();
objMsg.Body = strBody.ToString();
System.Web.Mail.SmtpMail.Send(objMsg);
}
}
}
}
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}


strEmail contains - name@email.com,name2@email.com,name3@email.com

6 replies

Badge +11
I haven't had a look at your code but I don't think this is where the problem lies...

Can you explain to me exactly where you send this email i.e. is it in an Escalation Action, is it it a Default Server Mail event, etc?

Also, how many Destination users are defined on the Activity where the mail is sent?

How many email messages are sent to each user?

Any correlation between number of mails sent and number of Destination users?

Regards,
Ockert
Badge +3
I am sending 1 email for the group.

name1, name2, name3 in the strEmail object.

It is in a default server email .

I get 4 notifications, there are 3 names. If i reduce the names to 1, i get 2 email notifications.
Badge +11
Thank you but I'm a little bit confused now...

I am sending 1 email for the group.

name1, name2, name3 in the strEmail object.

Understandable - that's what you're trying to do, right?
Send 1 email message to name1, name2, name3 in strEmail.

It is in a default server email.

How many Destination Users are defined in the Activity containing this default server mail event - note: nothing to do with email addresses but Destination Users - Right-click on Activity, select Properties and select Destination Rule.

What other events have you got in this Activity?

Maybe you should post your K2.net solution so that I can have a quick look at it.

Regards,
Ockert
Badge +3
My destination rule adds the users 1 at a time. I am sending in a group name and I wrote code to resolve the names. For each name I add them to the destination rule.

I have 4 names in total for this test. I have a group that contains 3 names and 1 for a user.

I'd be happy to send you my K2 solution, where should i send it?
Badge +11
This is where your problem lies...

From a previous post you said:
I get 4 notifications, there are 3 names.

In the last post you said:
I have 4 names in total for this test.

Remember, a copy of the whole Activity will be instantiated for EACH Destination User i.e. there will be 4 Activity Instance objects instantiated. Each one of these Activity Instances contains its own Mail Server Event which will send a mail to the 3 names specified resulting in each user getting 4 email messages.

If you've only got the Mail Server event in this Activity, it is not necessary to specify any Destination Users since it is a Server Event which will result in only 1 Activity Instance being created and therefore only one email message to each user.

Hope this helps,
Ockert
Badge +3
That was it. Thanks for your help.

Reply