0
votes

So i need to get informations such as :

  • Sender mail address (to later get his Domain profile informations)

  • Mail subject (which should be the "filepath" minus the "msg" extension anyway).

And then, replying to it just like i would push "ReplyAll" button in Outlook. So the reply needs to get the usual Headers such as "From : ....", "To : ...", "Cc : ..." and so on.
All i need is to change its subject, and delete the address depending on the "FromAddress" of the user that will push the button

I've read a bit here and there, and people are talking about a MailItem, but there's no informations about HOW to get this item or how to build it from a .msg file.

What i have to do comes after a specific user action.
The user is supposed to Drag&Drop the mail into a panel, from there i get its local path.

Thanks for your time !


Edit#1

I managed to find out to get informations and to set a .msg file to a MailItem :

    Outlook.Application appOutlook = new Outlook.Application();
    var email = (Outlook.MailItem)appOutlook.Session.OpenSharedItem(filepath);
    string getCC = "";
    string getFrom = ""; // From is never null
    string getTo = "";
    string getSubject = "";
    bool lengthCC = email.CC.HasValue();
    bool lengthTo = email.To.HasValue();
    bool lengthSubject = email.Subject.HasValue();
    if (lengthCC)
    {
        getCC = email.CC.ToString();
    }
    // and so on...
    //
    // Display it in MessageBox to confirm test succeeded :
    MessageBox.Show("CC : " + getCC +
                    "\nFrom : " + getFrom +
                    "\nTo : " + getTo +
                    "\nSubject : " + getSubject);
    email.Close(Outlook.OlInspectorClose.olDiscard);  

Now i just need to build the ReplyAll Body and add headers manually myself i guess...


Edit#2

No need to rewrite Headers apparently, doing so :

   Outlook._MailItem reply = email.ReplyAll();
   reply.To = getFrom;
   reply.CC = getCC;
   reply.Body = "SomeReplyMessage" + reply.Body;
   reply.Send();
   Marshal.ReleaseComObject(appOutlook);
   Marshal.ReleaseComObject(email);
   Marshal.ReleaseComObject(reply);  

But it erased the separator above the original message, i'll find a way to re-add it !!!


Edit#3

And there it is, the so-called "separator" wasn't displaying, because i wasn't re-stating an HTML Body ! So, to keep it you can do this :

        reply.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
        string ReplyMessageBody = String.Format("AddSome<br>HTMLCode<br>ThereAndHere<br>ButFinishWith : BodyTag</body>");
        reply.HTMLBody = ReplyMessageBody + reply.HTMLBody;  

Or simpler if you don't need your reply to be an HTML one :

        reply.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
        reply.HTMLBody = "AddSomeReplyMessage" + reply.HTMLBody;
2

2 Answers

0
votes

Outlook does not work directly wit MSG files - when you call CreateFromTemplate or even OpenSharedItem, Outlook creates a new item in its default store and imports the MSG or OFT file. It does not expose anything that would you let you figure out that the message came from a file; the item is indistinguishable from an item created directly using CreateItem or MAPIFolder.Items.Add.

0
votes

See edits on original question for answer !