open outlook

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • odelial
    New Member
    • May 2007
    • 4

    #1

    open outlook

    hello,
    i'm working on c# 2005, and i want to open m.outlook(2003) without sending the email, but open an email message.

    how can i do that?


    thanks,
    lala
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I had to do a lot of digging for this one when I needed it, so here's a little class:
    Code:
    static class OutlookEmail
        {
            private static Microsoft.Office.Interop.Outlook.Application oApp= new Microsoft.Office.Interop.Outlook.Application();
            private static Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
            private static Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;
    
            public static void CreateEmail(string[] toValues, string subjectValue, string bodyValue)
            {
                //oApp = new Microsoft.Office.Interop.Outlook.Application();
                oNameSpace = oApp.GetNamespace("MAPI");
                oNameSpace.Logon(null, null, true, true);
                oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
    
                Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
    
                string theTO = "";
                foreach(string toVal in toValues)
                {
                    //oMailItem.Recipients.Add(toVal);
                    theTO += toVal + "; ";
                }
                oMailItem.To = theTO;
                oMailItem.Subject = subjectValue;
                oMailItem.Body = bodyValue;
                //oMailItem.SaveSentMessageFolder = oOutboxFolder;
                oMailItem.Display(null);
            }
    }
    Be sure to also include a reference to:
    Microsoft Outlook 11.0 Object Library

    Comment

    • odelial
      New Member
      • May 2007
      • 4

      #3
      it works :)
      thanks you!!!!!

      Comment

      • mwalts
        New Member
        • May 2007
        • 38

        #4
        Originally posted by Plater
        I had to do a lot of digging for this one when I needed it, so here's a little class:
        Code:
        static class OutlookEmail
            {
                private static Microsoft.Office.Interop.Outlook.Application oApp= new Microsoft.Office.Interop.Outlook.Application();
                private static Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
                private static Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;
        
                public static void CreateEmail(string[] toValues, string subjectValue, string bodyValue)
                {
                    //oApp = new Microsoft.Office.Interop.Outlook.Application();
                    oNameSpace = oApp.GetNamespace("MAPI");
                    oNameSpace.Logon(null, null, true, true);
                    oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
        
                    Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
        
                    string theTO = "";
                    foreach(string toVal in toValues)
                    {
                        //oMailItem.Recipients.Add(toVal);
                        theTO += toVal + "; ";
                    }
                    oMailItem.To = theTO;
                    oMailItem.Subject = subjectValue;
                    oMailItem.Body = bodyValue;
                    //oMailItem.SaveSentMessageFolder = oOutboxFolder;
                    oMailItem.Display(null);
                }
        }
        Be sure to also include a reference to:
        Microsoft Outlook 11.0 Object Library
        That's neat, but if you don't mind me asking, why not just use mailto:whatever @someplace.ca,s omeotherguy@oth erplace.com?sub bject=blah&body =BlahAsWell

        If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

        Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

        Have fun,

        -mwalts

        Comment

        • prabunewindia
          New Member
          • Mar 2007
          • 199

          #5
          you can also refer the below article for more understanding

          outlook
          Prabu

          Originally posted by mwalts
          That's neat, but if you don't mind me asking, why not just use mailto:whatever @someplace.ca,s omeotherguy@oth erplace.com?sub bject=blah&body =BlahAsWell

          If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

          Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

          Have fun,

          -mwalts

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by mwalts
            That's neat, but if you don't mind me asking, why not just use mailto:whatever @someplace.ca,s omeotherguy@oth erplace.com?sub bject=blah&body =BlahAsWell

            If you run the above (well double check the mailto syntax, but you get the idea) as a process with UseShellExecute = true, it will open whatever your default mail program is in the same manner, regardless of if they have outlook installed.

            Your example does force it to be outlook though, which could be useful, and I'm sure gives you much greater control overall.

            Have fun,

            -mwalts

            Well the request was for the ability to open outlook, not the default mailer.

            As for Prabu, I believe I used some article I found here back when I created mine, but had to hack it apart to get it to work better. (I don't like having the "an application is trying to use outlook" popup coming up every 5secs as the article I read produced) I haven't gone through yours, but emailing help is always usefull. (I'm creating my own custom smtp class STILL)

            Comment

            Working...