question

OdalisReina-2779 avatar image
0 Votes"
OdalisReina-2779 asked JackJJun-MSFT commented

SSIS Script Task Help!!

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@gmail.com", "alavajessibel@gmail.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@gmail.com", "**");
client.Send(msg);
Dts.TaskResult = (int)ScriptResults.Success;
}

dotnet-csharpsql-server-integration-services
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please post your question in English. This is the English version of the forums. Alternatively please post your question in the forum specific to your locale.

1 Vote 1 ·

@OdalisReina-2779, Welcome to Microsoft Q&A, based on my test, cooldadtx's answer is correct, which could send the email sucessfully.
Therefore, Please check if you have done the following things.
First. Please ensure that you enable the Less secure app access.


Second. Please check if you have added the following namespace using:
203846-microsoftteams-image.png





0 Votes 0 ·
YitzhakKhabinsky-0887 avatar image
1 Vote"
YitzhakKhabinsky-0887 answered YitzhakKhabinsky-0887 edited

Hi @OdalisReina-2779,

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've already tried and it still doesn't work.

0 Votes 0 ·

@OdalisReina-2779,

Before any execution, are you able to successfully build the Script Task source code?
Via Build menu, 2nd option from the top with the icon.
And check the Output window pane.

0 Votes 0 ·
cooldadtx avatar image
1 Vote"
cooldadtx answered cooldadtx commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I don't get anything, only X in the script task

0 Votes 0 ·
cooldadtx avatar image cooldadtx OdalisReina-2779 ·

It writes to the log file. Go look at your execution log to see the exception. You might also need to actually turn on logging if you haven't already. ALternatively set a breakpoint in your code and step through it. We aren't going to be able to remotely debug this for you so you'll have to do the stepping yourself and tell us what the actual error is.

2 Votes 2 ·