Reputation: 17
void send_reply(Outlook.MailItem item, HashSet<string> names)
{
Outlook.MailItem eMail = item.Reply();
// want to open an email draft box for user to type in the email's content then return to the program here
eMail.Display();
foreach (string s in names)
{
eMail.To = s;
//MessageBox.Show("this is the guy we are sending to " + item.To);
eMail.Importance = Outlook.OlImportance.olImportanceHigh;
((Outlook._MailItem)eMail).Send();
}
}
Want to send a reply to a given mailitem but only to the email addresses specified in names. Issue I'm having is when I call eMail.Display() it only shows for like half a second at most then the draft auto closes and I send a blank reply email to everyone in names.
Anyone have any suggestions?
Upvotes: 0
Views: 696
Reputation: 404
The Display()
function returns immediately and makes your message to be sent empty.
You can wait by passing true
to the function:
//...
Outlook.MailItem eMail = item.Reply();
eMail.Display(true); // <-- here
//...
This will make the window Modal and will wait for user to close it.
Maybe you have also to check if the user closed it without a text inside or have the intention to undo the operation...
To do this maybe you can check the message status or register a handler to one (or both) of Close
(and Send
) events.
Upvotes: 1