0

我有一个 Outlook 插件,允许用户将电子邮件保存到数据库中。当用户保存电子邮件时,我会修改电子邮件主题,以便将其识别为已保存。

保存电子邮件可以通过两种方式进行。通过工具栏上的一个按钮,用户可以保存他们想要的任何电子邮件,还可以通过在将新电子邮件放入“已发送邮件”文件夹时出现的提示。两种方法都使用相同的表单来保存电子邮件!

好的,现在问题....

在保存电子邮件的过程中,我使用mailItem.SaveAs将其放入文件存储的方法。成功完成后,我想更改 Outlook 中仍然存在的电子邮件主题,以说明它已成功保存。我通过更改myItem.Subject然后使用该mailItem.Save方法保存更改来做到这一点。

当未通过提示方法保存电子邮件时,上述方法非常有效。因此,当用户在发送电子邮件后尝试保存电子邮件时,该mailItem.Save方法不起作用。

myItem.Save()如果我将行放在行之前,我已将其缩小到实际工作myItem.SaveAs(),但显然如果我这样做,我不能保证电子邮件实际上已正确保存。

那么有没有人知道mailItem.Save该方法在调用该方法后不工作的原因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() + " :: ");
    }
}
4

1 回答 1

1

如果这仍然与您相关:您可以使用自定义列,您可以在其中写入保存是否成功。

示例代码:

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

唯一的缺点是您必须将该字段添加到 Outlook 中显示的列中。(也许可以通过编程方式完成)

关于您的方法不起作用的原因:我可以想象,当您在发送电子邮件后更改主题时,Outlook 不喜欢它。

于 2012-11-20T09:01:57.470 回答