static void Main(string[] args)
 {
     Outlook.Application outlookApp = new Outlook.Application();
     Outlook.MailItem    mailItem   = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
     mailItem.Subject = "My Subject";
     mailItem.To      = "";
     mailItem.Attachments.Add(@"C:\test.pdf");
     mailItem.Body       = "This is my Body-Text";
     mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
     ((Outlook.ItemEvents_10_Event)mailItem).Close += MailItem_onClose;
     ((Outlook.ItemEvents_10_Event)mailItem).Send  += MailItem_onSend;
     //mailItem.Display(true);   // This call will make mailItem MODAL -
     // This way, you are not allowed to create another new mail, ob browse Outlook-Folders while mailItem is visible
     // Using ApplicationContext will wait until your email is sent or closed without blocking other Outlook actions.
     using (_context = new System.Windows.Forms.ApplicationContext())
     {
         mailItem.Display();
         System.Windows.Forms.Application.Run(_context);
     }
     if (mailWasSent)
     {
         System.Windows.Forms.MessageBox.Show("Email was sent");
     }
     else
     {
         System.Windows.Forms.MessageBox.Show("Email was NOT sent");
     }
 }
 //
 // GET: /email/
 public static void CreateMessageWithAttachment(string invoiceNumber)
 {
     try
     {
         Outlook.Application oApp = new Outlook.Application();
         Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
         Models.DYNAMICS_EXTEntities _db = new Models.DYNAMICS_EXTEntities();
         string recipient = null;
         string messageBody = null;
         #region set email recipients
         {
             ObjectParameter[] parameters = new ObjectParameter[1];
             parameters[0] = new ObjectParameter("InvoiceNumber", invoiceNumber);
             List<Models.EmailAddress> emailList = _db.ExecuteFunction<Models.EmailAddress>("uspGetEmailAddress", parameters).ToList<Models.EmailAddress>();
             if(!string.IsNullOrEmpty(emailList[0].Email.ToString()))
                 recipient = emailList[0].Email.ToString().Trim();
             else
                 recipient = " ";
             email.Recipients.Add(recipient);
         }
         #endregion
         //email subject                 
         email.Subject = "Invoice # " + invoiceNumber;
         #region set email Text
         {
             Models.EmailText emailText = _db.ExecuteFunction<Models.EmailText>("uspEmailText").SingleOrDefault();
             messageBody = emailText.EmailTextLine1.ToString().Trim() + "\n\n\n\n\n\n\n\n\n";
             messageBody += emailText.EmailTextLine2.ToString().Trim() + "\n";
             messageBody += emailText.EmailTextLine3.ToString().Trim();
             email.Body = messageBody;
         }
         #endregion
         #region email attachment
         {
             string fileName = invoiceNumber.Trim();
             string filePath = HostingEnvironment.MapPath("~/Content/reports/");
             filePath = filePath + fileName + ".pdf";
             fileName += ".pdf";
             int iPosition = (int)email.Body.Length + 1;
             int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
             Outlook.Attachment oAttach = email.Attachments.Add(filePath, iAttachType, iPosition, fileName);
         }
         #endregion
         
         email.Display();
         //uncomment below line to SendAutomatedEmail emails atomaticallly
         //((Outlook.MailItem)email).Send(); 
     }
     catch (Exception e)
     {
     }
 }
示例#3
0
        public void CreateOutlookAppointments()
        {
            var a = new Outlook.Application();

            Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)a.CreateItem(Outlook.OlItemType.olAppointmentItem);

            appointment.Subject    = "Feierabend";
            appointment.Start      = DateTime.Now;
            appointment.End        = appointment.Start.Date.AddDays(1);
            appointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
            appointment.ReminderMinutesBeforeStart = 15;
            appointment.ReminderSet = true;
            appointment.Save();
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // google form for Curry


            // outlook

            Microsoft.Office.Interop.Outlook.Application otApp = new Outlook.Application();                // create outlook object
            Outlook.MailItem  otMsg   = (Outlook.MailItem)otApp.CreateItem(Outlook.OlItemType.olMailItem); // Create mail object
            Outlook.Recipient otRecip = (Outlook.Recipient)otMsg.Recipients.Add(EmailUrl);
            otRecip.Resolve();                                                                             // validate recipient address
            otMsg.Subject = "Test Subject";
            otMsg.Body    = "Text Message";
            String sSource = AppDomain.CurrentDomain.BaseDirectory + "Test.txt";
        }
示例#5
0
    public void SendMail(string args)
    {
        try
        {
            var oApp   = new Outlook.Application();
            var oMsg   = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            var oRecip = (Outlook.Recipient)oMsg.Recipients.Add("*****@*****.**");
            oRecip.Resolve();
            oMsg.Subject = "Deskstop Standards: Required Items";
            oMsg.Body    = body
                           oMsg.Display(true);

            oMsg.Save();
            oMsg.Send();
            oRecip = null;
            oMsg   = null;
            oApp   = null;
        }
        catch (Exception e)
        {
            Console.WriteLine("{problem with email execution} Exception caught: ", e);
        }
        return;
    }