title: Unable to send mail from SSIS using script task
body: <p>I have created script task in SSIS and wrote C# program to send mail. it is like this.</p>
  
  <pre><code>public void Main()
      {
  
          MailMessage mail = new MailMessage("from@email.com", "to@gmail.com", "subject", "body");
          SmtpClient client = new SmtpClient("smtp.office365.com", 587);
          client.Credentials = new NetworkCredential("from@email.com", "password!!!");
          client.EnableSsl = true;
          client.Send(mail);
  
          Dts.TaskResult = (int)ScriptResults.Success;
  
      }
  </code></pre>
  
  <p>When i tried to run the program, it shows the following exception.</p>
  
  <pre><code>Exception has been thrown by the target of an invocation.
  
  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)
  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()
  </code></pre>
  
  <p>When i run this code in C# console mode it's working fine.</p>
  
  <p>I tried send mail task in SSIS, but it is not working. So i used script task.</p>
  
  <p>any ideas on how to solve this?</p>