簡體   English   中英

Outlook MailItem另存為

[英]Outlook MailItem Save/SaveAs

我有一個Outlook加載項,允許用戶將電子郵件保存到數據庫中。 當用戶確實保存電子郵件時,我會修改電子郵件主題,以便可以將其標識為已保存。

保存電子郵件可以通過兩種方式進行。 通過工具欄上的按鈕,該按鈕允許用戶保存所需的任何電子郵件,還通過在將新電子郵件放入“已發送郵件”文件夾中時出現的提示。 兩種方法都使用相同的表單來保存電子郵件!

好的,現在是問題..

在保存電子郵件的過程中,我使用mailItem.SaveAs方法將其放入文件存儲中。 成功完成此操作后,我想更改Outlook中仍然存在的電子郵件主題,以表示已成功保存。 我可以通過更改myItem.Subject ,然后使用mailItem.Save方法來保存更改來實現。

當未通過提示方法保存電子郵件時,以上方法非常適用。 因此,當用戶在發送電子郵件后嘗試保存電子郵件時, mailItem.Save方法不起作用。

我已經把范圍縮小到實際工作,如果我把myItem.Save()行前myItem.SaveAs()線,但很明顯,如果我這樣做,我不能保證電子郵件實際上是保存正常。

那么,有人知道在mailItem.Save方法之后, mailItem.SaveAs方法將不起作用的mailItem.SaveAs嗎?

預先感謝您對可能存在問題的任何建議。

編輯:代碼

if (_item is Outlook.MailItem) { // if the incoming item is an Outlook mail Item
    // cast as a mail item
    Outlook.MailItem myItem = (Outlook.MailItem)_item;
    if (directoryExists(directoryTemp)) { // if the temporary directory exists
        bool _profiled = true;
        // copy the item as type .msg in the temporary location
        myItem.SaveAs(saveTemp, Outlook.OlSaveAsType.olMSG);
        // setup impersonation to copy the file to a secure location
        PImpersonateUser _iU = new PImpersonateUser();
        // do impersonation
        try {
            _iU.Impersonate("******", "******", "******");
            if (File.Exists(savefile)) { // if file already exists in the location
                // delete existing file
                File.Delete(savefile);
            }
            // move the temporary file to the secure location with the proper name
            File.Move(saveTemp, savefile);
            string year = "";
            if (ipt_year.SelectedItem != null) { // else if year has been selected
                year = ipt_year.SelectedItem.ToString();
            }
            _profile.profileEmail(folderString(_subject_), _fileName, year);
        } catch (Exception e) {
            _profiled = false;
            // if impersonation fails cancel the impersonation
            _iU.Undo();
            // show error
            MessageBox.Show(e.Source + "\n\n" + e.Message + "\n\n" + e.StackTrace, "SaveAs() Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        } finally {
            _iU.Undo();
        }
        if (_profiled) { // if the email was profiled successfully
            // mark the original email as being profiled
            markAsProfiled();
        }
    } else {
        // if temporary file save fails throw error
        MessageBox.Show("Temporary Directory (" + directoryTemp + ") Does Not Exist!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

和markAsProfiled函數...


private void markAsProfiled() {
    if (_item is Outlook.MailItem) { // if the incoming item is an Outlook mail Item
        // cast as a mail item
        Outlook.MailItem myItem = (Outlook.MailItem)_item;
        // make sure subject doesnt already have a profiled flag in the subject
        _subject_ = _subject_.Replace("[PROFILED] - ", "");
        // add a profiled flag in the subject of the email
        myItem.Subject = "[PROFILED] - " + _subject_;
        // add a yellow flag to the email
        myItem.FlagIcon = Microsoft.Office.Interop.Outlook.OlFlagIcon.olYellowFlagIcon;
        // save email with changes made
        myItem.Save();
        //MessageBox.Show("Mark as Profiled :: " + myItem.Subject + " :: " + myItem.Saved.ToString() + " :: ");
    }
}

如果這仍然與您有關:可以使用自定義列,在其中可以編寫保存是否成功。

示例代碼:

 mail.UserProperties.Add("Profiled", Outlook.OlUserPropertyType.olText, true);
 mail.UserProperties["Profiled"].Value = "Yes";
 mail.Save();

唯一的缺點是您必須將字段添加到Outlook中顯示的列。 (也許可以通過編程來完成)

關於您的方法為什么行不通的原因:我可以想象當您在發送電子郵件后更改電子郵件的主題時,Outlook不喜歡它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM