A
Alphagmale
I have created a VSTO add-in that will take the selected message and
will attempt to execute forward or replyall depending upon the menu
command selected. The whole purpose of this exercise is to take a
standard email, convert to a new message class and update the user
properties (special fields) of the message.
The selected message is copied, its message class is changed and then
it is moved to a temporary personal folder (ConvertToIFGMessage).
Toward the later part of the processing the temporary folder is
scanned for all messages and presented to the user for editing
(SendIFGMessage).
My question and problem concerns the fact that both the ReplyAll and
Forward are returning a NULL reference. Can you offer any clues?
Even better is there a way to trace exactly what is happening?
private void ConvertToIFGMessage(Outlook.MailItem mail)
{
try
{
Outlook.MailItem copyMail = mail.Copy() as
Outlook.MailItem;
copyMail.MessageClass = "IPM.Note.IFGXChange";
copyMail.Save();
copyMail.Move(_oIFGDrafts);
Marshal.ReleaseComObject(copyMail);
copyMail = null;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
_ifgTechListener.Flush();
}
return;
}
private void SendIFGMessage(_eSendType eSendType)
{
try
{
foreach (object obj in _oIFGDrafts.Items)
{
if (obj is Outlook.MailItem)
{
Outlook.MailItem ifgDraftMail = obj as
Outlook.MailItem;
Outlook.MailItem ifgMail = null;
if(eSendType == _eSendType.eSTForward)
{
ifgMail =
((Outlook._MailItem)ifgDraftMail).Forward();
ifgMail.CC =
ifgDraftMail.SenderEmailAddress + ";" +
ifgDraftMail.To.ToString() + ";" +
ifgDraftMail.CC.ToString();
ifgMail.Body = "Message Forwarded to
IFGTech For Review" + ifgMail.Body.ToString();
}
else
{
ifgMail =
((Outlook._MailItem)ifgDraftMail).ReplyAll();
ifgMail.CC = ifgDraftMail.CC.ToString() +
";" + "P-US-Interfaces Tech";
Outlook.UserProperty uDateTimeProp =
ifgMail.UserProperties.Add("DateResponded",
Outlook.OlUserPropertyType.olDateTime, _Missing, _Missing);
uDateTimeProp.Value = System.DateTime.Now;
Outlook.UserProperty uRespondedProp =
ifgMail.UserProperties.Add("Responded",
Outlook.OlUserPropertyType.olYesNo, _Missing, _Missing);
uRespondedProp.Value = true;
}
ifgMail.Display(true);
ifgDraftMail.Delete();
}
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
_ifgTechListener.Flush();
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new
System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new
System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
will attempt to execute forward or replyall depending upon the menu
command selected. The whole purpose of this exercise is to take a
standard email, convert to a new message class and update the user
properties (special fields) of the message.
The selected message is copied, its message class is changed and then
it is moved to a temporary personal folder (ConvertToIFGMessage).
Toward the later part of the processing the temporary folder is
scanned for all messages and presented to the user for editing
(SendIFGMessage).
My question and problem concerns the fact that both the ReplyAll and
Forward are returning a NULL reference. Can you offer any clues?
Even better is there a way to trace exactly what is happening?
private void ConvertToIFGMessage(Outlook.MailItem mail)
{
try
{
Outlook.MailItem copyMail = mail.Copy() as
Outlook.MailItem;
copyMail.MessageClass = "IPM.Note.IFGXChange";
copyMail.Save();
copyMail.Move(_oIFGDrafts);
Marshal.ReleaseComObject(copyMail);
copyMail = null;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
_ifgTechListener.Flush();
}
return;
}
private void SendIFGMessage(_eSendType eSendType)
{
try
{
foreach (object obj in _oIFGDrafts.Items)
{
if (obj is Outlook.MailItem)
{
Outlook.MailItem ifgDraftMail = obj as
Outlook.MailItem;
Outlook.MailItem ifgMail = null;
if(eSendType == _eSendType.eSTForward)
{
ifgMail =
((Outlook._MailItem)ifgDraftMail).Forward();
ifgMail.CC =
ifgDraftMail.SenderEmailAddress + ";" +
ifgDraftMail.To.ToString() + ";" +
ifgDraftMail.CC.ToString();
ifgMail.Body = "Message Forwarded to
IFGTech For Review" + ifgMail.Body.ToString();
}
else
{
ifgMail =
((Outlook._MailItem)ifgDraftMail).ReplyAll();
ifgMail.CC = ifgDraftMail.CC.ToString() +
";" + "P-US-Interfaces Tech";
Outlook.UserProperty uDateTimeProp =
ifgMail.UserProperties.Add("DateResponded",
Outlook.OlUserPropertyType.olDateTime, _Missing, _Missing);
uDateTimeProp.Value = System.DateTime.Now;
Outlook.UserProperty uRespondedProp =
ifgMail.UserProperties.Add("Responded",
Outlook.OlUserPropertyType.olYesNo, _Missing, _Missing);
uRespondedProp.Value = true;
}
ifgMail.Display(true);
ifgDraftMail.Delete();
}
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
_ifgTechListener.Flush();
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new
System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new
System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}