SSIS Script Task Help!!

Odalis Reina 1 Reputation point
2022-05-19T18:55:19.757+00:00

Error
en System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
en System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
en System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
en System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
en Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

Code to send email

public void Main()
{
// TODO: Add your code here
MailMessage msg = new MailMessage("odalismiriam15@Stuff .com", "alavajessibel@Stuff .com"
, "Confirmación de migración de paquetes"
, "Se ha realizado con exito la ejecucion de paquetes de migración");
SmtpClient client = new SmtpClient("smtp.gmail.com", 25);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("odalismiriam@Stuff .com", "**********");
client.Send(msg);
Dts.TaskResult = (int)ScriptResults.Success;
}

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,437 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,094 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 24,831 Reputation points
    2022-05-19T20:09:20.173+00:00

    Hi @Odalis Reina ,

    gmail is using completely different ports: 465 or 587.
    Check it out here: gmail-email-settings

    And your entire c# code is very questionable.
    No subject, no body, etc.

    2 people found this answer helpful.

  2. Michael Taylor 45,986 Reputation points
    2022-05-19T20:37:18.223+00:00

    Set UseDefaultCredentials to false before you set the Credentials property.

    The port number doesn't seem correct for gmail. Verify in their docs.

    Wrap the code in a try-catch and grab the exception so you get the actual error message. A stack trace isn't useful here, the underlying error is.

    public void Main()
    {
       try
       {
          MailMessage msg = new MailMessage("odalismiriam15@gmail.com", "alavajessibel@gmail.com"
         SmtpClient client = new SmtpClient("smtp.gmail.com", 25);
         client.EnableSsl = true;
         client.DeliveryMethod = SmtpDeliveryMethod.Network;
         client.UseDefaultCredentials = false;
         client.Credentials = new NetworkCredential("odalismiriam@gmail.com", "**");
    
        client.Send(msg);
        Dts.TaskResult = (int)ScriptResults.Success;
       } catch (Exception e)
       {
          Dts.Events.FireError(0, "Error", e.Message, null, 0);
          Dts.TaskResult = (int)ScriptResults.Failure;
       };
    }
    
    2 people found this answer helpful.

  3. JOLY Aurelien 5 Reputation points
    2023-10-02T10:31:49.8266667+00:00

    I had a similar problem, but I want to had a screenshot to help debug these cases : After closing the cryptic error prompt, watch into your debug output, there will be a short yet more useful error message : [enter image description here

    ](https://i.stack.imgur.com/3QBkr.png)

    1 person found this answer helpful.
    0 comments No comments