Пример #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;
            }
        }
Пример #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;
            }
        }
Пример #3
0
        private async void button1_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application     outlookApplication = new Microsoft.Office.Interop.Outlook.Application();;
            Microsoft.Office.Interop.Outlook.AppointmentItem appointment        = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
            created_by = appointment.SendUsingAccount.UserName;
            ((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)appointment).Send += new Microsoft.Office.Interop.Outlook.ItemEvents_10_SendEventHandler(MailItemSendedHandler);
            meetingroom_Id = Convert.ToInt32(meetingroom_name);
            from           = dateTimePicker1.Value.Date.ToString("MM/dd/yyyy ") + dateTimePicker3.Value.TimeOfDay;
            to             = dateTimePicker2.Value.Date.ToString("MM/dd/yyyy ") + dateTimePicker4.Value.TimeOfDay;

            string url = domain + "/MeetingRooms/NewReservation?from=" + from + "&to=" + to + "&created_by=" + created_by +
                         "&meetingroom_Id=" + meetingroom_Id;

            using (var client = new HttpClient())
            {
                var response = client.GetAsync(url).Result;
                if (response.IsSuccessStatusCode)
                {
                    // by calling .Result you are performing a synchronous call
                    var responseContent = response.Content;
                    // by calling .Result you are synchronously reading the result
                    code = await response.Content.ReadAsAsync <string>();
                }
            }
            StringBuilder html = new StringBuilder();

            html = buildhtml();
            TimeSpan ConvertZoneDays = new TimeSpan(2, 0, 0);

            appointment.Body  = html.ToString();
            appointment.Start = DateTime.Parse(dateTimePicker1.Value.Date.ToString("MM/dd/yyyy"));
            appointment.End   = DateTime.Parse(dateTimePicker2.Value.Date.ToString("MM/dd/yyyy"));
            TimeZoneInfo newTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");

            appointment.StartUTC = TimeZoneInfo.ConvertTime(DateTime.Parse(from), newTimeZone);
            appointment.StartUTC = appointment.StartUTC.Subtract(ConvertZoneDays);
            appointment.EndUTC   = TimeZoneInfo.ConvertTime(DateTime.Parse(to), newTimeZone);
            appointment.EndUTC   = appointment.EndUTC.Subtract(ConvertZoneDays);
            appointment.Location = meetingroom_name;
        }
Пример #4
0
        public void Send_Sheets_woform(Office.IRibbonControl control)
        {
            string tempfile = Path.Combine(Path.GetTempPath(), Globals.ThisWorkbook.Name.ToString());
            Globals.ThisWorkbook.SaveCopyAs(tempfile);

            try
            {
                if (ServerDocument.IsCustomized(tempfile))
                {
                    ServerDocument.RemoveCustomization(tempfile);
                }
                Microsoft.Office.Interop.Outlook.Application outlookapp = new Microsoft.Office.Interop.Outlook.Application();
                MailItem eMail = (MailItem)outlookapp.CreateItem(OlItemType.olMailItem);
                eMail.Subject = "SidneyN from elance: Workbook Attached: " + Globals.ThisWorkbook.Name.ToString();
                eMail.Attachments.Add(tempfile);
                eMail.Display(true);
                File.Delete(tempfile);
            }
            catch (System.Exception e)
            {
                //Error Removing Customization and Sending email.
            }
        }
Пример #5
0
 public void SetApplication(Microsoft.Office.Interop.Outlook.Application application)
 {
     _application = application;
 }
Пример #6
0
        //    private void TestSendWord()
        //    {

        //        Microsoft.Office.Interop.Word.Application wd;
        //        Microsoft.Office.Interop.Word.Document doc;
        //        MailItem itm;
        //  String ID;
        // Boolean blnWeOpenedWord;

        // wd = new Microsoft.Office.Interop.Word.Application();

        //wd.Visible = true;

        //doc = wd.Documents.Open("C:\\Users\\this\toEmail.doc");
        //itm = doc.MailEnvelope.item;
        //itm.To = "*****@*****.**";
        //itm.Subject = "My Subject";
        //itm.Send();


        //doc.Close();
        //wd.Quit();

        //doc = null;
        //itm = null;
        //wd = null;


        //    }



        public static string DisplayAccountInformation()
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();

                // The Namespace Object (Session) has a collection of accounts.
                Accounts accounts = application.Session.Accounts;

                // Concatenate a message with information about all accounts.
                StringBuilder builder = new StringBuilder();

                // Loop over all accounts and print detail account information.
                // All properties of the Account object are read-only.
                foreach (Account account in accounts)
                {
                    // The DisplayName property represents the friendly name of the account.
                    builder.AppendFormat("DisplayName: {0}\n", account.DisplayName);

                    // The UserName property provides an account-based context to determine identity.
                    builder.AppendFormat("UserName: {0}\n", account.UserName);

                    // The SmtpAddress property provides the SMTP address for the account.
                    builder.AppendFormat("SmtpAddress: {0}\n", account.SmtpAddress);

                    // The AccountType property indicates the type of the account.
                    builder.Append("AccountType: ");
                    switch (account.AccountType)
                    {
                    case OlAccountType.olExchange:
                        builder.AppendLine("Exchange");
                        break;

                    case OlAccountType.olHttp:
                        builder.AppendLine("Http");
                        break;

                    case OlAccountType.olImap:
                        builder.AppendLine("Imap");
                        break;

                    case OlAccountType.olOtherAccount:
                        builder.AppendLine("Other");
                        break;

                    case OlAccountType.olPop3:
                        builder.AppendLine("Pop3");
                        break;
                    }

                    builder.AppendLine();
                }

                // Display the account information.
                return(builder.ToString());
            }
            catch (System.Exception ex)
            {
                throw new System.Exception(ex.Message);
            }
            //System.Windows.Forms.MessageBox.Show(builder.ToString());
        }