Click here to Skip to main content
15,502,574 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I create exe for sending the email parameter
to outlook(likeTo,Subject and path of the attachement file ),its working fine for outlook 2013 but when i use it for outlook 2010 then ,if outlook 2010 is open then it woking fine but when outlook 2010 is closed then at that time my exe is not working. I also mention my code in below
so, please check and if possible then give me the solution.
static void Main(string[] args)
            string to, sub,  path;
            to = sub = path = string.Empty;

            Console.WriteLine("Enter to");
            to = Console.ReadLine();
            Console.WriteLine("Enter sub");
            sub = Console.ReadLine();
            Console.WriteLine("Enter path");
            path = Console.ReadLine();
            Console.WriteLine("Please Wait....");
            CreateMessageWithAttachment(path, to, sub);

        public static void CreateMessageWithAttachment(string path, string to, string subject)

                Outlook.Application oApp = new Outlook.Application();
                Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));

                #region set email recipients


                //email subject                 
                email.Subject = subject;

                #region set email Text

                   // email.Body = body;

                #region email attachment
                    if (File.Exists(path))
                       // int iPosition = (int)email.Body.Length + 1;
                        int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                        Outlook.Attachment oAttach = email.Attachments.Add(path, iAttachType);


            catch (Exception e)


Updated 6-Dec-13 10:32am
Sebastian T Xavier 6-Dec-13 6:45am    
does it throw some exception? Why you have left the 'catch' unhandled?
Sergey Alexandrovich Kryukov 6-Dec-13 15:31pm    
It actually means "handled", with complete blocking of propagation of the exception. Really bad idea, in most cases.
Sebastian T Xavier 10-Dec-13 3:36am    
Yes: sometimes, it may take days to figure out the exact problem.

1 solution

You don't need Outlook to send emails, see here :[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900