title: C# sending email script in SSIS working on machine and not on another
body: <p>My colleague copied <a href="https://stackoverflow.com/questions/31739984/unable-to-send-mail-from-ssis-using-script-task">this solution</a> to send emails from SSIS using scripts, replaced the emails and variables with our sample gmail address which resulted with the below code:</p>
  
  <pre><code>using System;
  using System.Data;
  using Microsoft.SqlServer.Dts.Runtime;
  using System.Windows.Forms;
  using System.Net.Mail;
  using System.Net;
  
  namespace ST_24c8cd1fcaa741e9aec2d04071a225c8
  {
  [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
  public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  {
      public void Main()
      {
          // TODO: Add your code here
          MailMessage mail = new MailMessage("sample_sender@gmail.com", "sample_recipient@gmail.com", "subject", "body");
          SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
          client.EnableSsl = true;
          client.UseDefaultCredentials = false;
          client.Credentials = new NetworkCredential("sample_sender@gmail.com", "secret_password");
          client.Send(mail);
  
          Dts.TaskResult = (int)ScriptResults.Success;
      }
  }
  }
  </code></pre>
  
  <p>This solution works fine for him on his machine (not deployed to SQL server) but I receive the following error: </p>
  
  <blockquote>
    <p>Exception has been thrown by the target of an invocation.<br>
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
    arguments, Signature sig, Boolean constructor)    at
    System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
    Object[] parameters, Object[] arguments)    at
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
    invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)<br>
    at System.RuntimeType.InvokeMember(String name, BindingFlags
    bindingFlags, Binder binder, Object target, Object[] providedArgs,
    ParameterModifier[] modifiers, CultureInfo culture, String[]
    namedParams)    at
    Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()</p>
  </blockquote>
  
  <p>when executing the task. Even if I create a new package and copy his code into my script, it comes back with an error. Any ideas what might be causing this?  </p>