Exemplo n.º 1
0
        //private MailItem mailItem = null;
        //private Microsoft.Office.Interop.Outlook.TaskItem taskItem = null;
        //private int counter = 0;

        public static void sendmail(string address, string subject, string message)
        {
            MailItem mailItem = null;

            Microsoft.Office.Interop.Outlook.TaskItem taskItem = null;
            int counter = 0;

            try
            {
                Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();


                //  ae = new AddressEntry


                mailItem         = ((MailItem)myApp.CreateItem((OlItemType.olMailItem)));
                mailItem.Subject = subject;

                mailItem.To   = address;
                mailItem.Body = message;

                // Send the email to the customer
                ((_MailItem)mailItem).Send();
            }

            catch (System.Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public static void sendmail(string address, string subject, string TextMessage, string HTMLMessage, string[] Attachments, MessageType Type)
        {
            MailItem mailItem = null;

            Microsoft.Office.Interop.Outlook.TaskItem taskItem = null;
            int counter = 0;

            try
            {
                Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();


                //  ae = new AddressEntry


                mailItem         = ((MailItem)myApp.CreateItem((OlItemType.olMailItem)));
                mailItem.Subject = subject;

                mailItem.To = address;



                if (Type == MessageType.html)
                {
                    mailItem.HTMLBody = HTMLMessage;
                }
                else if (Type == MessageType.text)
                {
                    mailItem.Body = TextMessage;
                }

                if (Attachments.Length > 0)
                {
                    foreach (string item in Attachments)
                    {
                        //  Attachment att = new Attachment(item);
                        mailItem.Attachments.Add(item);
                    }
                }


                // Send the email to the customer
                ((_MailItem)mailItem).Send();
            }

            catch (System.Exception ex)
            {
                throw;
            }
        }