none
new outlook email

    Question

  • Hey all,

    I just want to be able to open a new mail in outlook.
    I've been fighting with this for quite some time now.

    Can't somebody point me in the right direction ? thx Smile


    Code Block

            private void menuItem7_Click(object sender, System.EventArgs e)
            {
               
               
                Outlook.Application outlook = new Outlook.ApplicationClass();

                try
                {
               
                    outlook = (Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                }
                catch (System.Exception ex)
                {
                   
                    outlook = new Outlook.ApplicationClass();
                }
               
                Outlook.MailItem mail = outlook.CreateItem(Outlook.OlItemType.olNoteItem);

               
               
                object objDummy = mail.GetInspector;
                mail.Recipients.Add("axel@mail.com");
                mail.Subject = "Betreff"; //
                mail.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
                mail.Display();
                // mail.Send();
            }


      Outlook.MailItem mail = outlook.CreateItem(Outlook.OlItemType.olNoteItem);
    --> is the problem.

    I've tried other combination,including making the mailItem, but them i'm not allowed.

    It cant be that hard to open a new mail with body and recipient filled in ? Sad

    little help please

    Wednesday, November 14, 2007 4:04 PM

Answers

All replies

  • I'm not familiar with Outlook InterOP so I can't help you directly. But I have two articles to suggest:

     

    Outlook with .Net 2.0

    and

    Programming Outlook with C#

     

    Hope this helps,

    Regards,

    Fábio

    Wednesday, November 14, 2007 4:24 PM


  • thank you for your answer, unfortunately they both show the correct way, which i used
    but  following line gives an error :



    Code Block

    Outlook.MailItem mail = outlook.CreateItem(Outlook.OlItemType.olMailItem);


    error =...\Form1.cs(1199): Cannot implicitly convert type 'object' to 'Outlook.MailItem'

    Actually, my VS 2003 doesn't have office.interop .. but i take care of it like this =

    Code Block

    Outlook.Application outlook = new Outlook.ApplicationClass();
    outlook = (Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");


    I'm so close .. any help ? Sad

    ( the site you gave assume that that first line works like a charm )
    Thursday, November 15, 2007 8:29 AM
  • never mind,i got i working.
    thx to those links Smile
    Thursday, November 15, 2007 10:45 AM
  • As i said I hate this new Outlook

    I cant attach a file when i reply or try to send an email and attach a file,,,, Im pissed

    Saturday, March 30, 2013 1:01 AM