title: SSIS send email using external xml template
body: <p>I need to send emails from an SSIS package, but the with email content in the form of an external xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;EmailContent&gt;
  &lt;FromMailId&gt;johndoe@email.com&lt;/FromMailId&gt;
      &lt;CC&gt;janedoe@email.com&lt;/CC&gt;
  &lt;BCC&gt;&lt;/BCC&gt;
  &lt;EmailSubject&gt;Email Subject Line&lt;/EmailSubject&gt;
  &lt;EmailBody&gt;
      Email Body here with some $variables$.   
      &lt;/EmailBody&gt;
  &lt;/EmailContent&gt;
  </code></pre>
  
  <p>I set up a test project where I'm using a SQL script task to save to a <strong>ResultObject</strong>. Then inside a <strong>ForEachLoopContainer</strong> I have a <strong>SendMailTask</strong>. There are different email templates that need to be sent based upon a value from the <strong>ResultObject</strong>. I need to check a variable in the ResultObject, and then based upon that value grab the corresponding email xml template. I'm guessing I need to achieve this using a C# <strong>ScriptTask</strong> instead of the <strong>SendMailTask</strong>, but I'm not sure how?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am writing a <strong>ScriptTask</strong> to copy the xml node values to variables. But I am receiving blank values? See code below:</p>
  
  <pre><code>        XmlTextReader reader = new XmlTextReader(email.xml);
          XmlDocument xDoc = new XmlDocument();
          xDoc.Load(reader);
  
          string EmailTo = xDoc.SelectSingleNode("EmailContent/FromMailId").InnerText;
          string EmailCc = xDoc.SelectSingleNode("EmailContent/CC").Value;
  </code></pre>