我有一个outlook加载项,允许用户将电子邮件保存到数据库中。当用户保存电子邮件时,我会修改电子邮件主题,以便将其标识为保存。Outlook MailItem保存/另存为
保存电子邮件可能发生在两个方面。通过工具栏上的一个按钮,用户可以保存他们想要的任何电子邮件,也可以通过在将新电子邮件放入已发送邮件文件夹时出现的提示进行操作。两种方法都使用相同的格式来保存电子邮件!
好了,现在的问题....
在保存电子邮件的过程中,我使用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() + " :: ");
}
}
您能否在al ittel中更详细地解释您的“即时工作流程”。你如何吸引发送等,因为有很多方法可以做到这一点。 – 76mel 2009-12-08 10:54:54
通过“提示”我的意思是,当addItem事件触发发送的项目文件夹时,它会询问用户是否要保存电子邮件。因此,电子邮件在通过发件箱并进入已发送邮件后触发事件。如果用户说“是”,他们想要保存电子邮件,那么主窗体会打开,首先引用关闭事件的电子邮件。 – Stuv 2009-12-09 03:05:31
好的,那么你的主表格中引用的电子邮件是怎么样的?是您的“主要”表单以任何方式更改电子邮件,因此需要保存。您可以检查isSaved属性。发布代码可能是一个想法。因为它听起来像是订单,或者你以某种方式使邮件变得肮脏。 – 76mel 2009-12-10 14:29:06