The references in Visual Studio to Interop.ADODB and Interop.CDO must be marked as follows: - Embed Interop Types: false // if not, you will see compile error 'CDO.MessageClass' has no constructors defined' - Copy to local: true // needs to be in the bin folder You can manually create an interop DLL by pointing Visual Studio to the CDO and ADODB dll's The interop DLL's included here have the benefit that they are signed with a strong name. This helps if you need to use them from a signed assembly Signing was done by disassembling the generated interop DLL's, signing them and re-compiling them with ILASM
Ejemplo n.º 1
0
        /// <summary>
        /// Sample to illustrate the use of CDOSYS.DLL from .net to parse EML files
        /// CDOSYS v.6 is a standard part of all windows versions (2012R2, 2008, 2003, 2000, XP, Vista, 8, 10): https://support.microsoft.com/en-us/kb/171440
        /// </summary>
        public static void Main()
        {
            var binFolderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var emlFilePath   = Path.Combine(binFolderPath, "sample.eml");
            var message       = CdoWrapper.LoadMessage(emlFilePath);

            Debug.WriteLine(message.Subject);
            Debug.WriteLine(message.TextBodyPart.GetString());
            Debug.WriteLine(message.HTMLBodyPart.GetString());
            var attachment = message.Attachments[1];

            Debug.WriteLine(attachment.FileName);
            Debug.WriteLine(attachment.GetString());
        }