0

I'm blocked with one problem when I tried to send email in one Sequence Workflow for SharePoint 2010.

I'm developing one sequential workflow where I have to send one email when one task is created in the workflow tasks. But the client requirement is to have the "Body" content of the email in one "Email Template List".

My doubt is:

How do I said to the SendEMail Activity to send the body from this template list.

SPListItem li = workflowProperties.Item; this.sendApproverEmail.Body = ""; this.sendApproverEmail.Subject = "";

Thank You

Hugo Marinho

1 Answer 1

1

From my understandings, you want to get data from a sharepoint list and send that data as email body using share point workflow that your creating in Visual studio 2010. Now there are numbers of ways to get data from a sharepoint list e.g. you can use SPquery (Linq & CAML) or client object model, I would prefer Object model as its easier.

    public void getEMailBody()
{
    // choose your site where you got "Email Template List"
    string strUrl = "http://mysite:5050/";
    using (SPSite site = new SPSite(strUrl))
    {
        using (SPWeb web = site.OpenWeb())
        {
            // choose the list
            SPList list = web.Lists["insert your list Name"];

            SPQuery myquery = new SPQuery();
            myquery.Query = "insert your query here depends on whats the name of your column where you stored body of email";

            // if you dosent insert query (myquery.Query ="") you will get all items

            SPListItemCollection items = list.GetItems(myquery);

            foreach (SPListItem item in items)
            {
                // check the item for null
                if (item != null)
                {
                    // do something
                }
            }
        }
    }
}

or you can do it this way

string strUrl = "http://mysite:5050/";
            using (SPSite site = new SPSite(strUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPListItemCollection listItems = web.Lists["List_Name"].Items;
                    //then get the item you want using foreach and SPListItem object
                }
            }

but still if you want to use LINQ and CAML you can see this Blog Post

I also find this link that might help you

Same scenario problem

or Sending Email using Workflow

Hope this helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.