Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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 :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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