• Sábado 27 de Abril de 2024, 03:57

Autor Tema:  Re: Descargar Email A La Pc  (Leído 1051 veces)

uriel_705

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Re: Descargar Email A La Pc
« en: Viernes 28 de Septiembre de 2007, 22:46 »
0
Hola!! Mi problema es el siguiente, estoy desarrollando una aplicación para realizar un monitoreo, actualmente envio los correos automaticamente desde una cuenta de gmail a cualquier correo ya se hotmail, yahoo, etc adjuntando una imagen.

El inconveniente es que necesito descargar los correos y las imagenes adjuntadas, para almacenarlas en la PC, y despues hacer uso de ellas.

Hasta el momento no he podido encontrar la manera de hacerlo, he buscado alguna libreria que me permita conectarme a una cuenta de correo pero solo la System.Net.Mail lo hace y es solo para enviar correos. Encontre que la libreria de Chikat.Net lo hace pero no he encontrado algun codigo para poder descargar correos referente a ella el codigo actual que tengo es este pero no me funciona pues a pesar que tengo correos en mi bandeja de entrada me indica que no hay ninguno... si alguien pudiera indicarme en que estoy mal o alguna otra manera de hacerlo...

De antemano les agradesco y gracias por su atención!!

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;
//se agrega la referencia Microsoft Outlook 11.0 Object Library
namespace Pruebasc
{
    class Program
    {
        public static int Main(string[] args)
        {

            try
            {
                // Create the Outlook application.
                // in-line initialization
                Outlook.Application oApp = new Outlook.Application();

                // Get the MAPI namespace.
                Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

                // Log on by using the default profile or existing session (no dialog box).
                oNS.Logon(Missing.Value, Missing.Value, false, true);

                // Alternate logon method that uses a specific profile name.
                // TODO: If you use this logon method, specify the correct profile name
                // and comment the previous Logon line.
                //oNS.Logon("profilename",Missing.Value,false,true);

                //Get the Inbox folder.
                Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

                //Get the Items collection in the Inbox folder.
                Outlook.Items oItems = oInbox.Items;

                // Get the first message.
                // Because the Items folder may contain different item types,
                // use explicit typecasting with the assignment.
                Outlook.MailItem oMsg = (Outlook.MailItem)oItems.GetFirst();
                if (oMsg == null)
                {
                    Console.WriteLine("Outlook no tiene correos para mostrar");

                }
                else
                {
                    //Output some common properties.
                    Console.WriteLine(oMsg.Subject);
                    Console.WriteLine(oMsg.SenderName);
                    Console.WriteLine(oMsg.ReceivedTime);
                    Console.WriteLine(oMsg.Body);

                    //Check for attachments.
                    int AttachCnt = oMsg.Attachments.Count;
                    Console.WriteLine("Attachments: " + AttachCnt.ToString());

                    //TO DO: If you use the Microsoft Outlook 10.0 Object Library, uncomment the following lines.
                    /*if (AttachCnt > 0)
                    {
                        for (int i = 1; i <= AttachCnt; i++)
                             Console.WriteLine(i.ToString() + "-" + oMsg.Attachments.Item(i).DisplayName);
                    }*/

                    //TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following lines.
                    if (AttachCnt > 0)
                    {
                        for (int i = 1; i <= AttachCnt; i++)
                            Console.WriteLine(i.ToString() + "-" + oMsg.Attachments.DisplayName);
                    }


                    //Display the message.
                    oMsg.Display(true);  //modal

                    //Log off.
                    oNS.Logoff();

                    //Explicitly release objects.
                    oMsg = null;
                    oItems = null;
                    oInbox = null;
                    oNS = null;
                    oApp = null;
                }
            }

                //Error handler.
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught: ", e);
            }

            // Return value.
            Console.ReadLine();
            return 0;


        }
    }
}