2008-11-19 5 views
9

Das ist, was ich bin mit E-Mail unter Verwendung von C# lesen:Lesen von E-Mail ohne Outlook App öffnen

outLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx); 
      Outlook.NameSpace olNameSpace = outLookApp.GetNamespace("mapi"); 

olNameSpace.Logon("xxxx", "xxxxx", false, true); 
Outlook.MAPIFolder oInbox = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); 
Outlook.Items oItems = oInbox.Items; 
MessageBox.Show("Total : " + oItems.Count); //Total Itemin inbox 
oItems = oItems.Restrict("[Unread] = true"); 
MessageBox.Show("Total Unread : " + oItems.Count); //Unread Items 
Outlook.MailItem oMsg; 


Outlook.Attachment mailAttachement; 
for (int i = 0; i < oItems.Count; i++) 
{ 
    oMsg = (Outlook.MailItem)oItems.GetFirst(); 

    MessageBox.Show(i.ToString()); 

    MessageBox.Show(oMsg.SenderName); 
    MessageBox.Show(oMsg.Subject); 
    MessageBox.Show(oMsg.ReceivedTime.ToString()); 
    MessageBox.Show(oMsg.Body); 

Das Problem, das ich bin vor ist diese Anwendung funktioniert nur, wenn die Outlook geöffnet wird auf der Maschine . Wenn Outlook geschlossen wird, wird eine Ausnahme ausgelöst:

Der Server ist nicht verfügbar. Wenden Sie sich an Ihren Administrator, wenn diese Bedingung weiterhin besteht.

Gibt es trotzdem ich kann lesen E-Mail mit Outlook öffnen?

Antwort

2

Sie werden wahrscheinlich in this laufen, wenn Outlook geschlossen ist.

Auch folgende this tutorial wird sicherstellen, dass Sie die richtigen Schritte Teil und Paket tun.

Viel Glück!

0

Sind Sie sicher, dass Sie Outlook als Proxy verwenden möchten?

peopleseems niedrigem Niveau mit einer solchen Aufgabe in C# zu behandeln (überraschend es keine integrierte Komponente im Rahmen ist ...)

Antwort bezüglich Mat, Erlösung ist in der Tat ein feines Produkt (benutzte es, um E-Mails bei der Ankunft in Outlook zu parsen), aber ich bezweifle, dass es funktionieren kann, ohne dass Outlook läuft.

0

Ich würde persönlich nicht Outlook als Proxy verwenden. Wenn Sie versuchen, einen Exchange-Informationsspeicher zu überwachen, würde ich WebDav verwenden. Ihr Exchange-Server muss dies unterstützen - aber wenn dies der Fall ist, handelt es sich um eine einfache XML-API. Nun, das API-Bit ist einfach, aber das XML ist ziemlich verworren. Aber nachdem Sie das in ein wenig Code eingekapselt haben, ist es ein Kinderspiel, es zu benutzen.

+0

Ich denke, es ist nicht relevant für die Frage. – Samuel

+0

Samuel, meine Antwort ist eine Ausarbeitung von "Nein, du kannst nicht". Ich dachte, es wäre hilfreicher! –

1

Diese Art einer alten Frage, aber ich werde es beantworten, da ich mit dem gleichen Problem für eine lange Zeit und die bisherigen Antworten auf dieser Seite gekämpft haben nicht wirklich mir helfen.

Ich musste ein Programm schreiben und Outlook verwenden, um eine E-Mail auf verschiedenen Rechnern mit verschiedenen UAC-Levels zu senden, und das habe ich nach langer Zeit herausgefunden.

using Outlook = Microsoft.Office.Interop.Outlook; 

// Create the Outlook application. 
Outlook.Application oApp = null; 

// Check whether there is an Outlook process running. 
int outlookRunning = Process.GetProcessesByName("OUTLOOK").Length; 
if (outlookRunning > 0) 
{ 
    // If so, use the GetActiveObject method to obtain the process and cast it to an Application object. 
    try 
    { 
     oApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; 
    } 
    catch (Exception) 
    { 
     oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Outlook.Application; 
    } 
    finally 
    { 
     // At this point we must kill Outlook (since outlook was started by user on a higher prio level than this current application) 
     // kill Outlook (otherwise it will only work if UAC is disabled) 
     // this is really a kind of last resort 
     Process[] workers = Process.GetProcessesByName("OUTLOOk"); 
     foreach (Process worker in workers) 
     { 
      worker.Kill(); 
      worker.WaitForExit(); 
      worker.Dispose(); 
     } 
    } 
} 
else 
{ 
    // If not, create a new instance of Outlook and log on to the default profile. 
    oApp = new Outlook.Application(); 
    Outlook.NameSpace nameSpace = oApp.GetNamespace("MAPI"); 
    try 
    { 
     // use default profile and DO NOT pop up a window 
     // on some pc bill gates fails to login without the popup, then we must pop up and lets use choose profile and allow access 
     nameSpace.Logon("", "", false, Missing.Value); 
    } 
    catch (Exception) 
    { 
     // use default profile and DO pop up a window 
     nameSpace.Logon("", "", true, true); 
    } 
    nameSpace = null; 
} 

// Done, now you can do what ever you want with the oApp, like creating a message and send it 
// Create a new mail item. 
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);