简体   繁体   中英

How to open outlook mail object as a draft email before sending?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM