0 votes

I'm trying to successfully run the C# code below but it keeps failing when I run the package, even though the code compiles successfully.

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

using Limilabs.Client.IMAP;
using Limilabs.Client.POP3;
using Limilabs.Client.SMTP;
using Limilabs.Mail;
using Limilabs.Mail.MIME;
using Limilabs.Mail.Fluent;
using Limilabs.Mail.Headers;
using System.Collections.Generic;

#endregion 

//.......name and class stuff....///
    using(Pop3 pop3 = new Pop3())
            {
               pop3.ConnectSSL("outlook.office365.com"); 
                pop3.UseBestLogin("USER", "PASSWORD");

                foreach (string uid in pop3.GetAll())
                {
                    IMail email = new MailBuilder()
                        .CreateFromEml(pop3.GetMessageByUID(uid));

                    Console.WriteLine(email.Subject);

                    // save all attachments to disk
                    foreach (MimeData mime in email.Attachments)
                    {
                        mime.Save(mime.SafeFileName);
                    }
                }

                pop3.Close();
            }
    //....now end the class and complete...///

Below is the error I am seeing.

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()

Has anyone seen this and fixed it before? the error message is very vague.

by (410 points)
edited by

1 Answer

+1 vote
 
Best answer

Don't specify port in the host. Either use proper overload or don't specify it at all:

pop3.ConnectSSL("outlook.office365.com"); 

As for the exception it doesn't seem to come from Mail.dll.

Try adding Mail.dll to GAC:

gacutil -i "c:\program files\limilabs\redistributables\net45\Mail.dll"

Use VS CMD running as administrator.

by (301k points)
selected by
I tried that too but I get the same error.
The exception doesn't seem to come from Mail.dll
It has to. Without the mail.dll code it passes.
Can you try adding Mail.dll to GAC.
(use gacutil -i "c:\program files\limilabs\redistributables\net45\Mail.dll")

2.
If 1. doesn't help: the Internet claims that having assembly copied to:
C:\Program files(x86)\SQL Server\110\Dts\Binn\
-or-
C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\
helped.
gacutil -i "c:\program files\limilabs\redistributables\net45\Mail.dll" worked.

I had to go into the VS CMD and run as admin.
...