Erste Anlagen aus Outlook

Bin ich 2 neue C# und ich, wir haben eine Aufgabe... ich habe das schreiben einer C# - code für den download der gesendeten E-Mail-Anhänge und Betreff von E-Mails aus Outlook 2007 auf einem lokalen Laufwerk oder eine bestimmte Lage. Wie mache ich das? Ich bin in der Lage, die Anlagen, die im Posteingang. Kann einer bitte helfen Sie mir immer die mails über Outlook gesendet wird?

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    this.Application.NewMail += new
      Microsoft.Office.Interop.Outlook.
      ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}

private void ThisApplication_NewMail()
{
    Outlook.MAPIFolder SentMail = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
    Outlook.Items SentMailItems = SentMail.Items;
    Outlook.MailItem newEmail = null;
    //SentMailItems = SentMailItems.Restrict("[Unread] = true");
    try
    {
        foreach (object collectionItem in SentMailItems)
        {
            newEmail = collectionItem as Outlook.MailItem;
            if (newEmail != null)
            {
                if (newEmail.Attachments.Count > 0)
                {
                    for (int i = 1; i <= newEmail.Attachments.Count; i++)
                    {
                        newEmail.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + newEmail.Attachments[i].FileName);
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        string errorInfo = (string)ex.Message
            .Substring(0, 11);
        if (errorInfo == "Cannot save")
        {
            MessageBox.Show(@"Create Folder C:\TestFileSave");
        }
    }
}

Vielen Dank im Voraus

InformationsquelleAutor Rashmi A M | 2012-02-18
Schreibe einen Kommentar