ユーザーが電子メールをデータベースに保存できるようにする Outlook アドインがあります。ユーザーがメールを保存するときは、メールの件名を変更して、保存されていることを識別できるようにします。
メールを保存するには、2 つの方法があります。ユーザーが必要な電子メールを保存できるようにするツールバーのボタンを介して、また、新しい電子メールが送信済みアイテム フォルダーに配置されたときに表示されるプロンプトを介して。どちらの方法でも同じフォームを使用してメールを保存できます。
さて、問題に....
電子メールを保存する過程で、この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() + " :: ");
}
}