none
URGENT : Send Email from the DMDynamic Workflow RRS feed

  • Question

  • Hello all,

    Please anyone have any ideas as to how I go about sending an email from a DMDynamic workflow? I know this has to be done in the code according to this msdn article http://archive.msdn.microsoft.com/P2010SolutionStarter/Thread/View.aspx?ThreadId=4530 which isn't explanatory enough.

    So I need a guide on exactly where in the code and what exactly should be entered to achieve this.

    Please I need replies as soon as possible. Your help will be really appreciated.

    Thanks.

    • Moved by epmXpertsModerator Friday, November 16, 2012 7:30 PM Moving to Customization Forum as its more relevant (From:Project Server General Questions and Answers)
    Friday, November 16, 2012 4:52 PM

Answers

  • though there are many ways to do it, but i would suggest dropping a code Activity within the workflow & then put your code behind to send the email notification, as the workflow executes these code snippets will automatically be executed within the workflow context

    refer to the snapshot below

    Let us know if this helps


    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com


    • Edited by epmXpertsModerator Friday, November 16, 2012 7:29 PM addition
    • Marked as answer by bami131 Saturday, November 17, 2012 12:18 PM
    Friday, November 16, 2012 7:23 PM
    Moderator

All replies

  • On what event are you looking for an email to be triggered as DMDynamic Workflow gives you an option to send email while an approval task is generated

    if other than that you are looking to send an email you need to either get that event tapped in code somehwere, (not sure where you want to trigger the email) and embed it either in "DynamicWorkflow.cs" or "ApprovalActivity.cs"

    other suggestion would be to look for project server event handler which you can use to trigger emails outside of the workflow, if not looking for approval workflow

    also can you elaborate more details on when & where you are looking to trigger the email?

     Let us know if this helps

    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    Friday, November 16, 2012 7:00 PM
    Moderator
  • Hi thanks for replying,

    I want to send an email to the initiator whenever an approval process has been completed. i.e the task created has either been approved or rejected. Please what part of the code do i do this and how? I am currently editing the "CanEndTaskApproval" method in the ApprovalActivity.cs but it dosen't seem to be making any difference as no emails are sent when this is done. This is what my method now looks like and it dosen't work.

    private void CanEndApprovalTask(object sender, ConditionalEventArgs e)
            {
                int positiveResults = 0;
                int negativeResults = 0;

                var officeTask = (OfficeTask)((Activity)sender).Parent.Parent.Parent;

                if (officeTask.TaskResults["Approved"] != null)
                {
                    positiveResults = Convert.ToInt32(officeTask.TaskResults["Approved"]);

                    SPWeb web = WorkflowProperties.Web;
                    StringDictionary headers = new StringDictionary();

                    headers.Add("from", "");
                    headers.Add("to", "");
                    headers.Add("subject", "Initiative Request Approved");
                    headers.Add("fAppendHtmlTag", "True"); //To enable HTML Tags

                    System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
                    strMessage.Append("Message from EPM:");

                    strMessage.Append("<span style='color:red;'> Your Initiative Request Form has been Approved </span>");
                    SPUtility.SendEmail(web, headers, strMessage.ToString());
                }


                if (officeTask.TaskResults["Rejected"] != null)
                {
                    negativeResults = Convert.ToInt32(officeTask.TaskResults["Rejected"]);

                    SPWeb web = WorkflowProperties.Web;
                    StringDictionary headers = new StringDictionary();

                    headers.Add("from", "");
                    headers.Add("to", "");
                    headers.Add("subject", "Initiative Request Rejected");
                    headers.Add("fAppendHtmlTag", "True"); //To enable HTML Tags

                    System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
                    strMessage.Append("Message from EPM:");

                    strMessage.Append("<span style='color:red;'> Your Initiative Request Form has been Rejected </span>");
                    SPUtility.SendEmail(web, headers, strMessage.ToString());
                }

    Thanks. 


    • Edited by bami131 Friday, November 16, 2012 7:13 PM
    Friday, November 16, 2012 7:11 PM
  • though there are many ways to do it, but i would suggest dropping a code Activity within the workflow & then put your code behind to send the email notification, as the workflow executes these code snippets will automatically be executed within the workflow context

    refer to the snapshot below

    Let us know if this helps


    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com


    • Edited by epmXpertsModerator Friday, November 16, 2012 7:29 PM addition
    • Marked as answer by bami131 Saturday, November 17, 2012 12:18 PM
    Friday, November 16, 2012 7:23 PM
    Moderator
  • Thanks a lot Sunil... This worked like magic!!!
    Saturday, November 17, 2012 12:18 PM
  • Hi Sunil.. i have a small challenge. I did this on my virtyal machine (one server farm) and it worked perfectly. When i tried it on production server, it didn't work, I'm confused. Any ideas please?

    though there are many ways to do it, but i would suggest dropping a code Activity within the workflow & then put your code behind to send the email notification, as the workflow executes these code snippets will automatically be executed within the workflow context

    refer to the snapshot below

    Let us know if this helps


    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com



    Sunday, November 18, 2012 6:10 PM
  • There could be several reasons why it might not be working, could be SMTP not working, could be workflow getting stuck somehwere could be error somewhere in the flow,
    suggested would be to put error handles or add instrumentation within workflow to capture the log & try to isolate the issue where its causing problem



    Thanks | Sunil Kr Singh | http://epmxperts.wordpress.com

    Monday, November 19, 2012 2:20 AM
    Moderator