//Send Email with password
        public bool SendMailWithOutlook(string subject, string htmlBody, string recipients, MailSendType sendType)
        {
            // create the outlook application.
            Outlook.Application outlookApp = new Outlook.Application();
            if (outlookApp == null)
            {
                return(false);
            }

            // create a new mail item.
            Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

            // set html body.
            // add the body of the email
            mail.HTMLBody = htmlBody;
            mail.Subject  = subject;
            mail.To       = recipients;

            if (sendType == MailSendType.SendDirect)
            {
                mail.Send();
            }
            else if (sendType == MailSendType.ShowModal)
            {
                mail.Display(true);
            }
            else if (sendType == MailSendType.ShowModeless)
            {
                mail.Display(false);
            }

            mail       = null;
            outlookApp = null;
            return(true);
        }
Exemple #2
0
        private void buttonEmail_Click(object sender, EventArgs e)
        {
            try
            {
                if (keyGenerated)
                {
                    Outlook.Application outlookApplication = new Outlook.Application();
                    Outlook.NameSpace   nameSpace          = outlookApplication.GetNamespace("MAPI");
                    Outlook.Folder      folderInbox        = (Outlook.Folder)nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                    Outlook.MailItem    mailItem           = (Outlook.MailItem)outlookApplication.CreateItem(Outlook.OlItemType.olMailItem);

                    mailItem.Subject = "Activation Information: " + productName + " for Revit 2013";

                    StringBuilder strBuilder = new StringBuilder();
                    strBuilder.AppendLine("Please activate " + productName + " with the following information.");
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Company Name: " + companyName);
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Identifier: " + identifier);
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Activation Code: " + labelLicense.Text);
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("**** All characters are case-sensitive. *****");

                    mailItem.Body = strBuilder.ToString();

                    mailItem.Display(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to send an email with the activation code.\n" + ex.Message, "mainForm:buttonEmail_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #3
0
        public void CreateNewMailWithEncryptedAttachments(string[] recipientsEmailAddresses, string[] attachedFiles)
        {
            Outlook.Application _application = null;
            Outlook.MailItem    mailItem     = null;

            try
            {
                _application = new Outlook.Application();

                mailItem = (Outlook.MailItem)_application.CreateItem(Outlook.OlItemType.olMailItem);

                mailItem.To = GetRecipientString(recipientsEmailAddresses);

                string[] encryptedPaths = EncryptFilesWithStormshieldDataFile(attachedFiles, recipientsEmailAddresses);
                foreach (string encryptedPath in encryptedPaths)
                {
                    mailItem.Attachments.Add(encryptedPath, Outlook.OlAttachmentType.olByValue);
                }

                mailItem.Display(true);
            }
            finally
            {
                if (mailItem != null)
                {
                    Marshal.ReleaseComObject(mailItem);
                }
                if (_application != null)
                {
                    Marshal.ReleaseComObject(_application);
                }
            }
        }
        private void create_Email_Draft(String filename, String master, String house)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook.MailItem    mailItem   = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

                mailItem.Subject    = "Test Subject";
                mailItem.To         = "*****@*****.**";
                mailItem.Body       = "Hi ! This is a test message";
                mailItem.Importance = Outlook.OlImportance.olImportanceLow;
                mailItem.Display(false);

                if (string.IsNullOrEmpty(filename) == false)
                {
                    // need to check to see if file exists before we attach !
                    if (!File.Exists(filename))
                    {
                        MessageBox.Show("Attached document " + filename + " does not exist", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        mailItem.Attachments.Add(filename, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                        mailItem.Attachments.Add(master, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                        mailItem.Attachments.Add(house, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }
                }

                mailItem.Close(Outlook.OlInspectorClose.olSave);
            }
            catch (Exception ex)
            {
                throw new Exception("Error occured trying to create email item --- " + Environment.NewLine + ex.Message);
            }
        }
Exemple #5
0
        public bool open()
        {
            try
            {
                Outlook.Application objApp = new Outlook.Application();
                Outlook.MailItem    mail   = null;
                mail = (Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem);

                mail.To      = this.to;
                mail.Subject = this.subject;
                mail.Body    = this.body;
                if (!String.IsNullOrEmpty(this.attachment))
                {
                    mail.Attachments.Add((object)this.attachment, Outlook.OlAttachmentType.olEmbeddeditem, 1, (object)this.subject);
                }


                mail.Display();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #6
0
        public void SendEmail()
        {
            Outlook.Application outlook;
            if ((outlook = GetApplication()) == null)
            {
                output.SetBusinessError("Outlook seems to not be installed on this machine. Aborting");
                return;
            }

            outlook.NewMail += new Outlook.ApplicationEvents_11_NewMailEventHandler(MailReceived);
            received         = false;
            Outlook.MailItem mail = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

            mail.Display();

            mail.To = outlook.Session.CurrentUser.Address;

            mail.Subject = input["subject"].ToString();

            mail.Body = "This is a test";

            mail.Send();

            while (!received)
            {
                System.Threading.Thread.Sleep(500);
            }
        }
 public override void SendEmail(string recipient, string cc, string bcc, string subject, string body)
 {
     ol.Application olApp = new ol.Application();
     ol.MailItem    eMail = (ol.MailItem)olApp.CreateItem(ol.OlItemType.olMailItem);
     eMail.To         = recipient;
     eMail.CC         = cc;
     eMail.BCC        = bcc;
     eMail.Subject    = subject;
     eMail.BodyFormat = (body.StartsWith("<html", StringComparison.CurrentCultureIgnoreCase)) ? ol.OlBodyFormat.olFormatHTML : ol.OlBodyFormat.olFormatPlain;
     if (eMail.BodyFormat == ol.OlBodyFormat.olFormatHTML)
     {
         eMail.HTMLBody = body;
     }
     if (eMail.BodyFormat == ol.OlBodyFormat.olFormatPlain)
     {
         eMail.Body = body;
     }
     if (AutoSend)
     {
         eMail.Send();
     }
     else
     {
         eMail.Save();
         eMail.Display(false);
     }
     Marshal.ReleaseComObject(eMail);
     eMail = null;
 }
Exemple #8
0
        private static void sendFromOutlook(string logarchivepath, string recipient, string body, string subject)
        {
            try
            {
                Outlook.Application app = new Outlook.Application();

                Outlook.MailItem message = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
                message.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
                message.Body       = body;
                message.Subject    = subject;
                message.Recipients.Add(recipient).Resolve();

                if (!String.IsNullOrWhiteSpace(logarchivepath))
                {
                    string filename       = Path.GetFileName(logarchivepath);
                    int    position       = message.Body.Length + 1;
                    int    attachmentType = (int)Outlook.OlAttachmentType.olByValue;
                    message.Attachments.Add(logarchivepath, attachmentType, position, filename);
                }

                message.Display();
            }
            catch (Exception ex)
            {
                throw new EMailSenderException("Cannot connect to Outlook", ex);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Outlook.Application  application = new Outlook.Application();
            Outlook.AddressEntry mailSender  = null;

            Outlook.Accounts accounts = application.Session.Accounts;

            foreach (Outlook.Account account in accounts)
            {
                mailSender = account.CurrentUser.AddressEntry;
            }

            Outlook.MailItem mail =
                application.CreateItem(
                    Outlook.OlItemType.olMailItem)
                as Outlook.MailItem;

            if (mailSender != null)
            {
                mail.To      = "[email protected]; [email protected]";
                mail.Subject = "Some Subject Matter";
                mail.Body    = "Some Body Text";
                mail.Sender  = mailSender;
                mail.Display(false);
            }
        }
Exemple #10
0
        /// <summary>
        /// process new mail from shared inbox
        /// </summary>
        /// <param name="NewItem"></param>
        private void SharedItems_ItemAdd(object NewItem)
        {
            Outlook.MailItem mail = (Outlook.MailItem)NewItem;    //New mail object
            MailParser(mail);                                     //process the mail for manifolds.
            /// <summary>
            /// The following code uses the tulpep/notification-popup library from nuget
            /// to display a new e-mail popup on the lower right corner of the screen
            /// as the shared inbox does not provide a new e-mail notification popup
            /// stock from Outlook.
            /// </summary>
            try
            {
                Size size          = new Size(48, 48);
                var  popupNotifier = new Tulpep.NotificationWindow.PopupNotifier();
                popupNotifier.TitleText     = "New Mail";
                popupNotifier.ContentText   = "From " + mail.SenderName + "\n" + mail.Subject;
                popupNotifier.IsRightToLeft = false;
                popupNotifier.Image         = image(mail);
                popupNotifier.ImageSize     = size;
                popupNotifier.Popup();
                popupNotifier.Click += Popup_Click;
            }
            catch (Exception) { }

            void Popup_Click(object sender, EventArgs e)
            {
                try
                {
                    mail.Display(true);
                }
                catch (Exception)
                { }
            }
        }
        private void btn_send_Click(object sender, EventArgs e)
        {
            //create a temp folder to put the pdf in
            Directory.CreateDirectory(tempFolder);
            Trace.WriteLine("Here's where the temp folder is: " + tempFolder.ToString());

            //store the document as a pdf in the temp location
            string sfileName     = doc.Name.Substring(0, doc.Name.Length - 5); //remove the .docx file extension
            string sFullpath_pdf = tempFolder + "\\" + sfileName + ".pdf";

            doc.ExportAsFixedFormat(sFullpath_pdf, Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport: false); // you'll need a doc range here

            //create a new mail
            Outlook.Application OutlookApp = new Outlook.Application();
            Outlook.MailItem    mail       = (Outlook.MailItem)OutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            mail.To      = txt_email.Text;
            mail.Subject = "CAMS form";
            mail.Body    = "Here is the form from your last session.";
            mail.Attachments.Add(sFullpath_pdf);
            mail.Display(true); //show the new Mail

            File.Delete(sFullpath_pdf);
            Trace.WriteLine("I deleted the files");
            //TODO: figure out how to also delete the directory...
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Create an object of type Outlook.Application
            Outlook.Application objOutlook = new Outlook.Application();

            //Create an object of type olMailItem
            Outlook.MailItem oIMailItem = objOutlook.CreateItem(Outlook.OlItemType.olMailItem);

            //Set properties of the message file e.g. subject, body and to address
            //Set subject
            oIMailItem.Subject = "This MSG file is created using Office Automation.";
            //Set to (recipient) address
            oIMailItem.To = "*****@*****.**";
            //Set body of the email message
            oIMailItem.HTMLBody = "<html><p>This MSG file is created using VBA code.</p>";

            //Add attachments to the message
            oIMailItem.Attachments.Add("image.bmp");
            oIMailItem.Attachments.Add("pic.jpeg");

            //Save as Outlook MSG file
            oIMailItem.SaveAs("testvba.msg");

            //Open the MSG file
            oIMailItem.Display();
        }
Exemple #13
0
                /// <summary>
                /// Формирование письма
                /// </summary>
                /// <param name="subject">тема письма</param>
                /// <param name="body">тело сообщения</param>
                /// <param name="to">кому/куда</param>
                public bool Format(string subject, string body, string to)
                {
                    bool bRes = false;

                    string msgAbort = string.Empty;

                    try {
                        msgAbort = string.Format(@"PanelTaskAutobookMonthValues.ReportEMailNSS.OutlookMessage::Format (to={0}) - не создан объект MS Outlook...", to);

                        if (Equals(m_outlookApp, null) == false)
                        {
                            _newMail            = (Outlook.MailItem)m_outlookApp?.CreateItem(Outlook.OlItemType.olMailItem);
                            _newMail.To         = to;
                            _newMail.Subject    = subject;
                            _newMail.Body       = body;
                            _newMail.Importance = Outlook.OlImportance.olImportanceNormal;
                            _newMail.Display();

                            bRes = true;
                        }
                        else
                        {
                            Logging.Logg().Error(msgAbort, Logging.INDEX_MESSAGE.NOT_SET);
                        }
                    } catch (Exception e) {
                        Logging.Logg().Exception(e, msgAbort, Logging.INDEX_MESSAGE.NOT_SET);
                    }

                    return(bRes);
                }
Exemple #14
0
        /// <summary>
        /// link to staff information setting function
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendEmail_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook.Application oApp = new Outlook.Application();

                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(showStaffInfo.Email);
                oRecip.Resolve();

                oMsg.Subject  = "annual leave remind";
                oMsg.HTMLBody = "Dear " + showStaffInfo.StaffName + ",<br/><br/>" +
                                " We kindly remind you that Your last year’s  Annual Leave still have " + showStaffInfo.LastyearRemains + " days left. It will be cleared  on  April 1st . <br/><br/>" +
                                "Best Regards<br/><br/>" +
                                "_____________________________________________<br/>" +
                                "Allen Wang<br/><br/>" +
                                "VOLVO Information Technology (TianJian)Co.,Ltd<br/>" +
                                "Telephone: +86-22-84808128<br/>" +
                                "Telefax:    +86-22-84808480<br/>" +
                                "E-mail: [email protected]<br/>";

                oMsg.Display(true);

                oRecip = null;
                oMsg   = null;
                oApp   = null;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error!" + ex);
            }
        }
Exemple #15
0
    private void DecryptButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
    {
      // Get the selected item in Outlook and determine its type.
      Outlook.Selection outlookSelection = Application.ActiveExplorer().Selection;
      if (outlookSelection.Count <= 0)
        return;

      object selectedItem = outlookSelection[1];
      Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;

      if (mailItem == null)
      {
        MessageBox.Show(
            "OutlookGnuPG can only decrypt mails.",
            "Invalid Item Type",
            MessageBoxButtons.OK,
            MessageBoxIcon.Error);

        return;
      }

      // Force open of mailItem with auto decrypt.
      _autoDecrypt = true;
      mailItem.Display(true);
//      DecryptEmail(mailItem);
    }
Exemple #16
0
        private void CreateMailItem()
        {
            //MessageBox.Show(name);

            string body = "Customer Name : " + lblName.Text +
                          Environment.NewLine + "Legal ID: " + lblLegal.Text +
                          Environment.NewLine + "Card Number: " + lblCard.Text +
                          Environment.NewLine + "Product: " + lblProduct.Text +
                          Environment.NewLine + "Source: " + lblSource.Text +
                          Environment.NewLine + "Interested: " + lblInterest.Text +
                          Environment.NewLine + "Available Balance: " + lblInterest.Text +
                          Environment.NewLine + "Remarks: " + lblInterest.Text +
                          Environment.NewLine + "Staff ID: " + Environment.UserName.ToString();

            Outlook.Application app      = new Outlook.Application();
            Outlook.MailItem    mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
            mailItem.Subject = "This is the subject";
            mailItem.To      = "*****@*****.**";

            crosssell cro = new crosssell();

            mailItem.Body = "";
            //mailItem.Attachments.Add(logPath);//logPath is a string holding path to the log.txt file
            mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
            mailItem.Display(true);
        }
 private void send(Outlook.MailItem mail)
 {
     ga("clicked");
     string name = mail.Sender.Address;
     //DialogResult result = MessageBox.Show("Send HK response to " + name,"Confirmation...", MessageBoxButtons.YesNo);
     //if (result == DialogResult.Yes)
     {
         // MessageBox.Show(ThisAddIn.User);
         Outlook.MailItem reply = mail.Reply();
         try
         {
             if (template == null)
             {
                 fetch();
             }
             sent           = false;
             reply.CC       = template.cc;
             reply.HTMLBody = getBody();
             reply.Subject  = template.subject;
             reply.Display();
             ((Outlook.ItemEvents_10_Event)reply).Send  += Ribbon1_Send;
             ((Outlook.ItemEvents_10_Event)reply).Close += Ribbon1_Close;
         }
         catch (Exception)
         {
             MessageBox.Show("Could not Reply");
         }
     }
 }
Exemple #18
0
        private void btnContactSupport_Click(object sender, EventArgs e)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application app =
                    Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
                Microsoft.Office.Interop.Outlook.MailItem mailItem =
                    app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                mailItem.Subject = "DC-OSS Rate Card Contact Support";
                mailItem.To      = "*****@*****.**";

                mailItem.Display(true);
            } catch (System.Runtime.InteropServices.COMException ex) {
                Microsoft.Office.Interop.Outlook.Application app =
                    new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.MailItem mailItem =
                    app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                mailItem.Subject = "DC-OSS Rate Card Contact Support";
                mailItem.To      = "*****@*****.**";

                mailItem.Display(true);
            }
        }
        private void BtnEmailItem_Click(object sender, EventArgs e)
        {
            var attachmentList = new List <string>();

            string attachmentLocation = "";



            Outlook.Application outlookApp = new Outlook.Application();
            Outlook.MailItem    mailItem   = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            mailItem.Subject = "";
            mailItem.To      = "";


            foreach (DataGridViewRow r in dataGridView1.SelectedRows)
            {
                int rowindex = r.Index;

                int quoteID = Convert.ToInt32(dataGridView1.Rows[rowindex].Cells[0].Value.ToString());
                int itemID  = Convert.ToInt32(dataGridView1.Rows[rowindex].Cells[1].Value.ToString());
                int revID   = Convert.ToInt32(dataGridView1.Rows[rowindex].Cells[2].Value.ToString());

                attachmentLocation = @"\\designsvr1\solidworks\Door Designer\Specifications\Project " + quoteID.ToString() + @"\\Quotations\Revision " + revID.ToString() + @"\\Quotation" + quoteID.ToString() + "-" + itemID.ToString() + "-" + revID.ToString() + ".pdf";

                var attachments = mailItem.Attachments;
                var attachment  = attachments.Add(attachmentLocation);
                mailItem.Attachments.Add(attachmentLocation);
                attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/jpeg");
                attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "myident"); // Image identifier found in the HTML code right after cid. Can be anything.
                mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", true);
            }



            // Set body format to HTML

            mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

            foreach (var attachmentGrab in attachmentList)
            {
            }



            string msgHTMLBody = "";

            mailItem.HTMLBody = msgHTMLBody;
            mailItem.Display(true);

            try
            {
                mailItem.HTMLBody = "" + mailItem.HTMLBody;
            }

            catch

            {
                // MessageBox.Show("This document has not yet been generated by driveworks, please try again later", "Try again later", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #20
0
        private void ButtonClose_Click(object sender, EventArgs e)
        {
            timerCheckStatus.Enabled = false;
            buttonClose.Enabled      = false;

            try {
                myMail.Display();
                Close();
                Dispose();
                return;
            } catch (Exception) {
                myMail = FindMail(myMailIndex, outBox);
            }

            try {
                myMail.Display();
            } catch (Exception) {
                ShowStatus("Transmission failure", Color.Red);
                ShowComment("Check the OutBox.", Color.Black);
                WaitClosing(5);
            } finally {
                Close();
                Dispose();
            }
        }
Exemple #21
0
        /// <summary>
        /// Method, that creates a Mail Item
        /// </summary>
        private void CreateMailItem()
        {
            //Outlook.MailItem mailItem = (Outlook.MailItem)
            // this.Application.CreateItem(Outlook.OlItemType.olMailItem);
            Outlook.Application app       = new Outlook.Application();
            Outlook.MailItem    mailItem  = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
            Outlook.Recipient   recipient = app.Session.CreateRecipient(sender);
            mailItem.Subject = this.subject;
            mailItem.To      = this.to;
            mailItem.CC      = this.cc;
            mailItem.Body    = this.body;

            if (this.filePaths.Count > 0)
            {
                foreach (string fileName in this.filePaths)
                {
                    string absolute_path = Path.Combine(CBZ.AppPath + fileName);
                    mailItem.Attachments.Add(Path.GetFullPath((new Uri(absolute_path)).LocalPath), Outlook.OlAttachmentType.olByValue, 1, fileName.Remove(0, 14));
                }
            }

            mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
            mailItem.Display(false);
            mailItem.Send();
        }
        //========================================================================================
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            Outlook.Application application = new Outlook.Application();

            mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Modify End Date Request.oft") as Outlook.MailItem;



            mail.HTMLBody = mail.HTMLBody.Replace("RequestorName", "" + txtFirstName.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("TicketNumber", "" + txtTicketNumber.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("FullnameDetails", "" + txtFullname.Text + "");
            if (checkBoxPermanent.Checked)
            {
                mail.HTMLBody = mail.HTMLBody.Replace("Date", "Permanent");
            }
            else
            {
                mail.HTMLBody = mail.HTMLBody.Replace("Date", "" + txtdate.Text + "");
            }

            mail.HTMLBody = mail.HTMLBody.Replace("RecipientEmail", "" + txtRecipientEmail.Text + "");
            mail.To       = txtEmailAddress.Text;
            //mail.CC = txtRecipientEmail.Text;
            mail.Subject = txtTicketNumber.Text.ToString() + "- Modify End Date Request";
            //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
            mail.Display(false);
        }
Exemple #23
0
        private void SendServiceAnniversaryWishInAdvance(EmployeeProfile emp)
        {
            string name         = emp.EmpName;
            string email        = DecorateEmailFromAlias(emp.Alias);
            string yearsWorking = (DateTime.Now.Year - emp.DateOfJoining.Year).ToString();

            Outlook.MailItem mailItem = (Outlook.MailItem)
                                        this.Application.CreateItem(Outlook.OlItemType.olMailItem);

            mailItem.Subject  = "WISH " + name + " SERVICE ANNIVERSARY IN ADVANCE!!!";
            mailItem.To       = email;
            mailItem.HTMLBody = "<HTML>Hey " +
                                "<br><h2>Do you want to wish " + name + " in advance as you may not wish on weekend???</h2>" +
                                "<br><br><h2>" +
                                emp.EmpName +
                                "'s SERVICE ANNIVERSARY!</h2><br><br>" + "<h4>Name: " +
                                emp.EmpName +
                                "<br>Joining Date: " +
                                emp.DateOfJoining.ToString("dd-MMMM-yyyy") +
                                "<br><br>" +
                                name + " has completed " + yearsWorking + " years working with us!" +
                                "</h4><br><br>";
            mailItem.Importance = Outlook.OlImportance.olImportanceLow;
            mailItem.Display(false);
        }
Exemple #24
0
        /// <summary>Handles the onAction event of the OpenMessage button.
        /// </summary>
        /// <param name="control">The source control of the event.</param>
        public void OpenMessage(Office.IRibbonControl control)
        {
            if (!string.IsNullOrWhiteSpace(currentSearchText))
            {
                // Obtain a reference to selection.
                Outlook.Selection selection = ActiveExplorer.Selection;
                if (selection.Count == 0)
                {
                    return;
                }

                // Open the first item that is a supported Outlook item.
                // The selection may contain various item types.
                IEnumerator e = ActiveExplorer.Selection.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current is Outlook.MailItem)
                    {
                        Outlook.MailItem item = e.Current as Outlook.MailItem;
                        item.Display();
                        FindInInspector(item.GetInspector, currentSearchText);
                        break;
                    }
                    else if (e.Current is Outlook.MeetingItem)
                    {
                        Outlook.MeetingItem item =
                            e.Current as Outlook.MeetingItem;
                        item.Display();
                        FindInInspector(item.GetInspector, currentSearchText);
                        break;
                    }
                }
            }
        }
Exemple #25
0
        private void linkEmail_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                Outlook.Application outlookApplication = new Outlook.Application();
                Outlook.NameSpace   nameSpace          = outlookApplication.GetNamespace("MAPI");
                Outlook.Folder      folderInbox        = (Outlook.Folder)nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.MailItem    mailItem           = (Outlook.MailItem)outlookApplication.CreateItem(Outlook.OlItemType.olMailItem);

                mailItem.Subject = "Activation Request: " + trialMaker.ProductName + " for Revit 2013";

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.AppendLine("I'm sending a request for the " + trialMaker.ProductName + " with the following information.");
                strBuilder.AppendLine("");
                strBuilder.AppendLine("Company Name: " + trialMaker.CompanyName);
                strBuilder.AppendLine("");
                strBuilder.AppendLine("**** All characters are case-sensitive. *****");
                strBuilder.AppendLine("**** Our HOK team will contact you shortly. *****");

                mailItem.Body = strBuilder.ToString();

                mailItem.Display(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to request an activation code.\n" + ex.Message, "TrialMakerForm:linkEmail_LinkClicked", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #26
0
        /// <summary>
        /// Open an item in outlook folder
        /// </summary>
        /// <param name="item">Outlook item used to open</param>
        public static void DisplayAndCloseItem(object item)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                object[]            args       = new object[] { };
                object retVal = item.GetType().InvokeMember("Class", BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, item, args);
                Outlook.OlObjectClass outlookItemClass = (Outlook.OlObjectClass)retVal;
                switch (outlookItemClass)
                {
                case Outlook.OlObjectClass.olMail:
                    Outlook.MailItem omail = (Outlook.MailItem)item;
                    omail.Display(false);
                    omail.Close(Outlook.OlInspectorClose.olSave);
                    break;

                case Outlook.OlObjectClass.olDocument:
                    Outlook.DocumentItem odocument = (Outlook.DocumentItem)item;
                    odocument.Display(true);
                    odocument.Close(Outlook.OlInspectorClose.olSave);
                    break;

                case Outlook.OlObjectClass.olRecurrencePattern:

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public void CreateMail(string subject, string body, string attachment = "")
        {
            try
            {
                Outlook.Application oApp = new Outlook.Application();
                Outlook.MailItem    oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                oMsg.Subject    = subject;
                oMsg.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
                oMsg.HTMLBody   = body;
                if (attachment != string.Empty)
                {
                    oMsg.Attachments.Add(attachment, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                }
                oMsg.Display(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.Close();
            }
        }
 /// <summary>
 /// Open the task
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">EventArgs</param>
 private void lstTasks_DoubleClick(object sender, EventArgs e)
 {
     if (this.lstTasks.SelectedIndices.Count != 0)
     {
         OLTaskItem task = this.lstTasks.SelectedItems[0].Tag as OLTaskItem;
         if (task != null)
         {
             if (task.OriginalItem is Outlook.MailItem)
             {
                 Outlook.MailItem mail = task.OriginalItem as Outlook.MailItem;
                 mail.Display(true);
             }
             else if (task.OriginalItem is Outlook.ContactItem)
             {
                 Outlook.ContactItem contact = task.OriginalItem as Outlook.ContactItem;
                 contact.Display(true);
             }
             else if (task.OriginalItem is Outlook.TaskItem)
             {
                 Outlook.TaskItem t = task.OriginalItem as Outlook.TaskItem;
                 t.Display(true);
             }
             else
             {
                 // Do nothing
             }
             // At the end, synchronously "refresh" tasks in case they have changed
             this.RetrieveTasks();
         }
     }
 }
Exemple #29
0
        void OutlookMail()
        {
            try
            {
                DateTime DTime = DateTime.Now;
                gvwEODProcess.ExportToExcelOld(_core.ReportPathOut + "\\EODMail" + DTime.Hour + DTime.Minute + DTime.Second + ".xls");

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

                oMsg.Subject = "Өдөр өндөрлөлтийн процесс";
                oMsg.Body    = _core.TxnDate.ToShortDateString() + "-н өдөр өндөрлөлтийн процессийн тайлан .";
                String             sSource      = _core.ReportPathOut + "\\EODMail" + DTime.Hour + DTime.Minute + DTime.Second + ".xls";
                String             sDisplayName = "Хавсралт файл";
                int                iPosition    = 1;
                int                iAttachType  = (int)Outlook.OlAttachmentType.olByValue;
                Outlook.Attachment oAttach      = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
                oMsg.Display(true);

                oAttach = null;
                oMsg    = null;
                oApp    = null;
            }
            catch
            {
                MessageBox.Show("Алдаа гарлаа .");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Outlook.Application  application = new Outlook.Application();
            Outlook.AddressEntry addrEntry   = null;

            Outlook.Accounts accounts =
                application.Session.Accounts;


            foreach (Outlook.Account account in accounts)
            {
                addrEntry =
                    account.CurrentUser.AddressEntry;
            }

            Outlook.MailItem mail =
                application.CreateItem(
                    Outlook.OlItemType.olMailItem)
                as Outlook.MailItem;

            if (addrEntry != null)
            {
                //Set Sender property.
                mail.Sender = addrEntry;
                mail.Display(false);
            }
        }