Пример #1
1
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Create a new Application Class
            _Application outlook = new Outlook.Application();
            // Create a MailItem object
            MailItem item = (MailItem)outlook.CreateItemFromTemplate("test.msg", Type.Missing);
            // Access different fields of the message
            System.Console.WriteLine(string.Format("Subject:{0}", item.Subject));
            System.Console.WriteLine(string.Format("Sender Email Address:{0}", item.SenderEmailAddress));
            System.Console.WriteLine(string.Format("SenderName:{0}", item.SenderName));
            System.Console.WriteLine(string.Format("TO:{0}", item.To));
            System.Console.WriteLine(string.Format("CC:{0}", item.CC));
            System.Console.WriteLine(string.Format("BCC:{0}", item.BCC));
            System.Console.WriteLine(string.Format("Html Body:{0}", item.HTMLBody));
            System.Console.WriteLine(string.Format("Text Body:{0}", item.Body));

        }
        //========================================================================================
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            Outlook.Application application = new Outlook.Application();
            if (CBSharedDA.Checked && !CBLyncA.Checked)
            {
                mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Network Account Creation - OnlySharedDrive.oft") as Outlook.MailItem;
            }
            else if (!CBSharedDA.Checked && CBLyncA.Checked)
            {
                mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Network Account Creation - OnlyLync.oft") as Outlook.MailItem;
            }
            else if (CBSharedDA.Checked && CBLyncA.Checked)
            {
                mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Network Account Creation.oft") as Outlook.MailItem;
            }
            else if (!CBSharedDA.Checked && !CBLyncA.Checked)
            {
                mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Network Account Creation - NoLyncAndSharedDrive.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("RecipientEmail", "" + txtRecipientEmail.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("UsernameDetails", "" + txtusername.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("PasswordDetails", "" + txtPassword.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("AccessType", "" + cmbAccessType.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("FolderPath", "" + txtFolderPath.Text + "");

            mail.To      = txtEmailAddress.Text;
            mail.CC      = txtRecipientEmail.Text;
            mail.Subject = txtTicketNumber.Text.ToString() + "- Network Account Creation";
            //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
            mail.Display(false);
        }
Пример #3
0
 //To open a template.
 public void opentemp(string id)
 {
     fn = id;
     Outlook.MailItem omail;
     omail = oapp.CreateItemFromTemplate(strPath + "/templates/" + id + ".msg");
     omail.Display(true);
 }
Пример #4
0
        private void Button1_Click(object sender, EventArgs e)
        {
            questionList.Items.Clear();
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (Directory.Exists(Configuration.pathFileTemplate))
            {
                openFileDialog.InitialDirectory = Configuration.pathFileTemplate;
                openFileDialog.Filter           = "oft files (*.oft)|*.oft|All files (*.*)|*.*";
                openFileDialog.RestoreDirectory = false;
                openFileDialog.Title            = "Template for email";

                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string filePath = openFileDialog.FileName;
                    label1.Show();
                    label1.Text = "You are editing: " + openFileDialog.SafeFileName;

                    Application   app  = new Application();
                    MailItem      mail = app.CreateItemFromTemplate(filePath) as MailItem;
                    List <String> questionsFromTemplate = Tools.GetQuestionsFromEmail(mail.Body);


                    foreach (String s in questionsFromTemplate)
                    {
                        questionList.Items.Add(s);
                    }
                    templateZaladowany = true;
                }
            }
            else
            {
                MessageBox.Show("First use 'Create Form' button from menu.", "Warning");
            }
        }
Пример #5
0
        public bool CreateItemFromTemplateAndCheck()
        {
            OlDefaultFolders defaultFolder = OlDefaultFolders.olFolderDrafts;
            Application      app = new Application();
            Folder           folder = app.Session.GetDefaultFolder(defaultFolder) as Folder;
            MailItem         mail = app.CreateItemFromTemplate(filePath, folder) as MailItem;
            List <string>    templateLines, receviedMailLines;
            string           body         = mailItem.Body;
            string           templateBody = mail.Body;

            receviedMailLines = Tools.GetEmailLineByLine(body);
            templateLines     = Tools.GetEmailLineByLine(templateBody);
            bool conteinsAllTemplateLine = true;

            foreach (string s in templateLines)
            {
                if (!body.Contains(s))
                {
                    conteinsAllTemplateLine = false;
                    break;
                }
            }

            if (conteinsAllTemplateLine == true && Tools.HaveWeAnswersForAllQuestions(templateLines, receviedMailLines))
            {
                //MessageBox.Show("OK");
                return(true);
            }
            else
            {
                //MessageBox.Show("Format is not ok.");
                return(false);
            }
        }
Пример #6
0
        public void SendOutlook(string template, string subject, string to, string cc, string bcc, string body, DataTable dt, List <string> attachments)
        {
            Outlook.Application app = new Outlook.Application();
            app.ActiveWindow();
            Outlook.MailItem mail;
            mail = app.CreateItemFromTemplate(template.Contains(@":\")
                                ? template
                                : System.IO.Directory.GetCurrentDirectory() + '\\' + template) as Outlook.MailItem;
            mail.Subject = String.IsNullOrEmpty(subject) ? (String.IsNullOrEmpty(mail.Subject) ? "Untitled" : mail.Subject) : subject;
            mail.To      = String.IsNullOrEmpty(to) ? mail.To : to;
            mail.CC      = String.IsNullOrEmpty(cc) ? mail.CC : cc;
            mail.BCC     = String.IsNullOrEmpty(bcc) ? mail.BCC : bcc;
            attachments.ForEach(x => mail.Attachments.Add(x));
            if (String.IsNullOrEmpty(mail.To) && String.IsNullOrEmpty(mail.CC) && String.IsNullOrEmpty(mail.BCC))
            {
                throw new System.Exception("Error, there is no recepients specified");
            }

            mail.HTMLBody = mail.HTMLBody.Replace("{message}", body);
            mail.HTMLBody = mail.HTMLBody.Replace("{table}", dt != null ? (dt.Rows.Count > 0 ? GetHTMLTable(dt) : "") : "");
            mail.Send();
            app.GetNamespace("MAPI").SendAndReceive(true);

            var releaseResult = Marshal.ReleaseComObject(app);
        }
Пример #7
0
        //========================================================================================
        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);
        }
        protected override void Execute(CodeActivityContext context)
        {
            String TO, CC, BCC, SUBJECT, BODY;

            if (TemplatePath.Get(context).Contains(".eml"))
            {
                Message emlMessage = ReadMessage(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context));
                TO      = emlMessage.To;
                CC      = emlMessage.CC;
                BCC     = emlMessage.BCC;
                SUBJECT = emlMessage.Subject;
                BODY    = String.IsNullOrEmpty(emlMessage.HTMLBody)?emlMessage.TextBody:emlMessage.HTMLBody;
            }
            else if (TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg"))
            {
                try
                {
                    Outlook.Application app      = new Outlook.Application();
                    Outlook.MailItem    template = app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem;
                    TO      = template.To;
                    CC      = template.CC;
                    BCC     = template.BCC;
                    SUBJECT = template.Subject;
                    BODY    = String.IsNullOrEmpty(template.HTMLBody) ? template.Body : template.HTMLBody;
                }
                catch
                {
                    throw new System.Exception("Error, .oft and .msg files can only be read if you have Outlook installed, try using a .eml as a template");
                }
            }
            else
            {
                throw new System.Exception("Invalid template format, please use a '.oft', '.msg', or '.eml' template.");
            }

            SUBJECT = String.IsNullOrEmpty(Subject.Get(context)) ? (String.IsNullOrEmpty(SUBJECT) ? "Untitled" : SUBJECT) : Subject.Get(context);
            TO      = String.IsNullOrEmpty(To.Get(context)) ? TO : To.Get(context);
            CC      = String.IsNullOrEmpty(Cc.Get(context)) ? CC : Cc.Get(context);
            BCC     = String.IsNullOrEmpty(Bcc.Get(context)) ? BCC : Bcc.Get(context);
            BODY    = BODY.Replace("{message}", String.IsNullOrEmpty(Body.Get(context))?"":Body.Get(context));
            BODY    = BODY.Replace("{table}", DT.Get(context) != null ? (DT.Get(context).Rows.Count > 0 ? GetHTMLTable(DT.Get(context)) : "") : "");
            MailMessage mail = new MailMessage(From.Get(context), TO, SUBJECT, BODY);

            mail.Bcc.Add(BCC);
            mail.IsBodyHtml = true;
            mail.CC.Add(CC);
            SmtpClient client = new SmtpClient
            {
                Port                  = Port.Get(context),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                EnableSsl             = EnableSSL,
                Host                  = Server.Get(context),
                Credentials           = new System.Net.NetworkCredential(Email.Get(context), Password.Get(context)),
                Timeout               = 30000
            };

            client.Send(mail);
        }
Пример #9
0
        private void sendEmail(string name, string email, ref OutlookApp outlookApp)
        {
            MailItem mailItem = outlookApp.CreateItemFromTemplate(emailTemplatePath);

            mailItem.HTMLBody = mailItem.HTMLBody.Replace("%name%", name);
            mailItem.To       = email;

            mailItem.Send();
        }
Пример #10
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     Outlook.Application application = new Outlook.Application();
     Outlook.MailItem    mail        = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Remote Citrix Access Request.oft") as Outlook.MailItem;
     mail.HTMLBody = mail.HTMLBody.Replace("SERVICEREQUESTNUMBER", "" + txtSCREQ.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("Requestorsfirstname", "" + txtFirstName.Text + "");
     mail.Subject  = txtTicketNumber.Text.ToString() + "- VPN Remote Access Request";
     mail.To       = txtEmailAddress.Text;
     //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
     mail.Display(false);
 }
Пример #11
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     Outlook.Application application = new Outlook.Application();
     Outlook.MailItem    mail        = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - ShareFile Access And Installation.oft") as Outlook.MailItem;
     mail.HTMLBody = mail.HTMLBody.Replace("AU-SDXXXX", "" + txtTicketNumber.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("Requestorname", "" + txtFirstName.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("ComputerName", "" + txtCompName.Text + "");
     mail.Subject  = txtTicketNumber.Text.ToString() + "- ShareFile Access & Installation";
     mail.To       = txtRequestorEmail.Text;
     //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
     mail.Display(false);
 }
Пример #12
0
        public Application(string templatePath, string subject, string to, string cc, string bcc, string body, string from, int port, DataTable dt, bool ssl, string host, string email, string password, List <string> inputs)
        {
            EMAIL    = email;
            PASSWORD = password;
            HOST     = host;
            SSL      = ssl;
            Port     = port;
            FROM     = from;
            Inputs   = inputs;
            if (templatePath.Contains(".eml"))
            {
                Message emlMessage = ReadMessage(templatePath.Contains(":\\") ? templatePath : System.IO.Directory.GetCurrentDirectory() + '\\' + templatePath);
                TO      = emlMessage.To;
                CC      = emlMessage.CC;
                BCC     = emlMessage.BCC;
                SUBJECT = emlMessage.Subject;
                BODY    = String.IsNullOrEmpty(emlMessage.HTMLBody) ? emlMessage.TextBody : emlMessage.HTMLBody;
            }
            else if (templatePath.Contains(".oft") || templatePath.Contains(".msg"))
            {
                try
                {
                    Outlook.Application app      = new Outlook.Application();
                    Outlook.MailItem    template = app.CreateItemFromTemplate(templatePath.Contains(":\\")
                                                ? templatePath
                                                : System.IO.Directory.GetCurrentDirectory() + '\\' + templatePath) as Outlook.MailItem;
                    TO      = template.To;
                    CC      = template.CC;
                    BCC     = template.BCC;
                    SUBJECT = template.Subject;
                    BODY    = String.IsNullOrEmpty(template.HTMLBody) ? template.Body : template.HTMLBody;
                }
                catch (IOException)
                {
                    throw;
                }
                catch
                {
                    throw new System.Exception("Error, .oft and .msg files can only be read if you have Outlook installed, try using a .eml as a template");
                }
            }
            else
            {
                throw new System.Exception("Invalid template format, please use a '.oft', '.msg', or '.eml' template.");
            }

            SUBJECT = String.IsNullOrEmpty(subject) ? (String.IsNullOrEmpty(SUBJECT) ? "Untitled" : SUBJECT) : subject;
            TO      = String.IsNullOrEmpty(to) ? TO : to;
            CC      = String.IsNullOrEmpty(cc)? CC : cc;
            BCC     = String.IsNullOrEmpty(bcc) ? BCC :bcc;
            BODY    = BODY.Replace("{message}", String.IsNullOrEmpty(body) ? "" : body);
            BODY    = BODY.Replace("{table}", dt != null ? (dt.Rows.Count > 0 ? GetHTMLTable(dt) : "") : "");
        }
Пример #13
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            Outlook.Application application = new Outlook.Application();
            Outlook.MailItem    mail        = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - MS Lync Account Creation.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("EmailAddress", "" + txtEmailAddress.Text + "");
            mail.Subject  = txtTicketNumber.Text.ToString() + "- MS Lync Account Creation";
            mail.To       = txtEmailAddress.Text;

            //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
            mail.Display(false);
        }
Пример #14
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     Outlook.Application application = new Outlook.Application();
     Outlook.MailItem    mail        = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Audio Web Conferencing.oft") as Outlook.MailItem;
     mail.HTMLBody = mail.HTMLBody.Replace("RequestorName", "" + txtxRequestorFName.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("RecipientFirstName", "" + txtRecipientFirstName.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("TicketNumber", "" + txtHPSM.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("ComputerName", "" + txtComputerName.Text + "");
     mail.To       = txtRequestorEmail.Text;
     mail.CC       = txtRecipientEmail.Text;
     mail.Subject  = txtHPSM.Text.ToString() + "- Audio Web Conferencing";
     mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
     mail.Display(false);
 }
Пример #15
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     Outlook.Application application = new Outlook.Application();
     Outlook.MailItem    mail        = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Shared Drive Access.oft") as Outlook.MailItem;
     mail.HTMLBody = mail.HTMLBody.Replace("RequestorFirstName", "" + txtFirstName.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("RecipientFirstName", "" + txtRecipientFirstName.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("AccessType", "" + cmbAccessType.Text + "");
     mail.HTMLBody = mail.HTMLBody.Replace("FolderPath", "" + txtFolderPath.Text + "");
     mail.To       = txtEmailAddress.Text;
     mail.CC       = txtRecipientEmail.Text;
     mail.Subject  = txtTicketNumber.Text.ToString() + "- Shared Drive Access";
     //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
     mail.Display(false);
 }
        public static void ImportFormToPersonalFormsLibrary(string path, string name)
        {
            if (null == m_Application)
            {
                Initialise();
            }
            try
            {
                Outlook.FormDescription formDescription = null;
                Outlook.MailItem        mailItem        = null;
                Outlook.AppointmentItem appointmentItem = null;
                dynamic formTemplate = m_Application.CreateItemFromTemplate(path);
                if (formTemplate is Outlook.MailItem)
                {
                    mailItem        = formTemplate as Outlook.MailItem;
                    formDescription = mailItem.FormDescription;
                }
                else if (formTemplate is Outlook.AppointmentItem)
                {
                    appointmentItem = formTemplate as Outlook.AppointmentItem;
                    formDescription = appointmentItem.FormDescription;
                }
                ;
                if (formDescription != null)
                {
                    formDescription.Name = name;
                    formDescription.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry);
                    ReleaseObject(formDescription);
                    formDescription = null;
                }

                if (mailItem != null)
                {
                    ReleaseObject(mailItem);
                }
                if (appointmentItem != null)
                {
                    ReleaseObject(appointmentItem);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unable to import custom form. Error: " + exception.ToString());
            }
            finally
            {
            }
        }
Пример #17
0
        private void CreateItemFromTemplate()
        {
            // Create the Outlook application.
            Outlook.Application oApp = new Outlook.Application();

            Outlook.Folder folder =
                oApp.Session.GetDefaultFolder(
                    Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
            Outlook.MailItem mail =
                oApp.CreateItemFromTemplate(
                    @"C:\Users\sabagsa\AppData\Roaming\Microsoft\Templates\TemplateOutlook.oft", folder) as Outlook.MailItem;
            mail.Subject = "Congratulations";
            mail.Attachments.Add(@"C:\Users\sabagsa\Pictures\169387.jpg",
                                 Outlook.OlAttachmentType.olByValue, Type.Missing,
                                 Type.Missing);
            mail.Save();
        }
Пример #18
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Create a new Application Class
            _Application outlook = new Outlook.Application();
            // Create a MailItem object
            MailItem item = (MailItem)outlook.CreateItemFromTemplate("test.msg", Type.Missing);

            // Access different fields of the message
            System.Console.WriteLine(string.Format("Subject:{0}", item.Subject));
            System.Console.WriteLine(string.Format("Sender Email Address:{0}", item.SenderEmailAddress));
            System.Console.WriteLine(string.Format("SenderName:{0}", item.SenderName));
            System.Console.WriteLine(string.Format("TO:{0}", item.To));
            System.Console.WriteLine(string.Format("CC:{0}", item.CC));
            System.Console.WriteLine(string.Format("BCC:{0}", item.BCC));
            System.Console.WriteLine(string.Format("Html Body:{0}", item.HTMLBody));
            System.Console.WriteLine(string.Format("Text Body:{0}", item.Body));
        }
Пример #19
0
        public static void automaticReply(MailItem email)
        {
            if (!checkIfTemplateWasSend)
            {
                //ORANGE CATEGORY
                //oznaczCalaKonwersacjeKategoria(email, "You Must Decide");
                ///////////////
                /*MessageBox.Show("Musisz wysłać dopiero template.");*/
            }
            else if (checkIfFitToTemplate)
            {
                //GREEN CATEGORY
                oznaczCalaKonwersacjeKategoria(email, "Good Response");
                ////////////

                /*MessageBox.Show("NIE ODSYŁAMY bo zgadza się template :)" +
                 *  "\nTemplateWasSend: " + checkIfTemplateWasSend +
                 *  "\nTemplateFilled: " + checkIfFitToTemplate);*/
            }
            else if (!checkIfFitToTemplate && checkIfTemplateWasSend)
            {
                /////////////
                /*MessageBox.Show("ODSYŁAMY automatycznie bo chamy niemyte nie czytajoXD");*/
                DialogResult result = MessageBox.Show("Do you want to send template once again? \n" + email.Subject + ",\n" + Tools.ShowAllReceivers(), "Confirmation", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Outlook.Application oApp         = new Outlook.Application();
                    MailItem            emailToReply = oApp.CreateItemFromTemplate(pathForTemplate) as MailItem;
                    emailToReply.Subject = "RE: " + email.Subject;
                    emailToReply.To      = email.ReplyAll().To;
                    if (email != null)
                    {
                        Outlook.MailItem replyMail = email.Reply();
                        replyMail.HTMLBody = emailToReply.HTMLBody + replyMail.HTMLBody;
                        replyMail.To       = email.ReplyAll().To;
                        replyMail.Send();
                    }
                }
                //RED CATEGORY
                oznaczCalaKonwersacjeKategoria(email, "Bad Response");
            }
        }
Пример #20
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (checkTemplate)
            {
                foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
                {
                    Outlook.Application oApp         = new Outlook.Application();
                    MailItem            emailToReply = oApp.CreateItemFromTemplate(loadData.GetPathFile()) as Outlook.MailItem;
                    emailToReply.Subject = "RE: " + email.Subject;

                    emailToReply.To = email.ReplyAll().To;

                    //recivers = reciversAll.ToArray();
                    reciversAll = new List <String>();
                    foreach (String k in questionList.Items)
                    {
                        reciversAll.Add(k);
                    }
                    recivers = reciversAll.ToArray();


                    /*foreach (String s in recivers)
                     * {
                     *  //MessageBox.Show(s);
                     * }*/

                    if (email != null)
                    {
                        Outlook.MailItem replyMail = email.Reply();
                        replyMail.HTMLBody = emailToReply.HTMLBody + replyMail.HTMLBody;
                        replyMail.To       = String.Join("; ", recivers);
                        //replyMail.Display(true);
                        replyMail.Send();
                    }
                }
                Close();
            }
            else
            {
                MessageBox.Show("First choose your template", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #21
0
        //========================================================================================
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            Outlook.Application application = new Outlook.Application();

            mail = application.CreateItemFromTemplate(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Access\AU-SDXXXX - Employee Account and Email Reactivation.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("UsernameDetails", "" + txtusername.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("PasswordDetails", "" + txtPassword.Text + "");
            mail.HTMLBody = mail.HTMLBody.Replace("EmailDetails", "" + txtRecipientFirstName.Text + "");

            mail.To = txtEmailAddress.Text;
            //mail.CC = txtRecipientEmail.Text;
            mail.Subject = txtTicketNumber.Text.ToString() + "- Employee Account and Email Reactivation";
            //mail.Attachments.Add(AppDomain.CurrentDomain.BaseDirectory + @"\EmailTemplates\Attachments\Test.txt");
            mail.Display(false);
        }
Пример #22
0
        public static void Send(string TemplatePath, string To = null, string Subject = null, string Body = null, string AttachmentPath = null, string BCC = null, Dictionary<string, string> BodyReplacements = null, string From = null)
        {
            OL.Application app = new OL.Application();
            OL.MailItem mail = app.CreateItemFromTemplate(TemplatePath) as OL.MailItem;

            if (!string.IsNullOrEmpty(To))
                mail.To = To;
            if (!string.IsNullOrEmpty(From))
                mail.SentOnBehalfOfName = From;
            if (!string.IsNullOrEmpty(BCC))
                mail.BCC = BCC;
            if (!string.IsNullOrEmpty(Subject))
                mail.Subject = Subject;
            if (!string.IsNullOrEmpty(Body))
                mail.Body = Body;
            if (BodyReplacements != null)
                foreach (KeyValuePair<string, string> item in BodyReplacements)
                    mail.HTMLBody = mail.HTMLBody.Replace(item.Key, item.Value);
            if (!string.IsNullOrEmpty(AttachmentPath))
                mail.Attachments.Add(AttachmentPath);
            mail.Display(false);
        }
Пример #23
0
        public bool checkIfThereIsATemplate()
        {
            OlDefaultFolders defaultFolder = OlDefaultFolders.olFolderDrafts;
            Application      app = new Application();
            Folder           folder = app.Session.GetDefaultFolder(defaultFolder) as Folder;
            MailItem         mail = app.CreateItemFromTemplate(filePath, folder) as MailItem;
            List <string>    templateLines, receviedMailLines;
            string           body         = mailItem.Body;
            string           templateBody = mail.Body;

            receviedMailLines = Tools.GetEmailLineByLine(body);
            templateLines     = Tools.GetEmailLineByLine(templateBody);
            bool conteinsAllTemplateLine = true;

            foreach (string s in templateLines)
            {
                if (!body.Contains(s))
                {
                    conteinsAllTemplateLine = false;
                    return(conteinsAllTemplateLine);
                }
            }
            return(conteinsAllTemplateLine);
        }
Пример #24
0
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi =
            gridView1.CalcHitInfo((sender as System.Windows.Forms.Control).PointToClient(System.Windows.Forms.Control.MousePosition));
            DataRow FocusRow;
            if (hi.RowHandle >= 0)
            {
                FocusRow = gridView1.GetDataRow(hi.RowHandle);
                string strType = FocusRow.ItemArray[3].ToString();
                string strPath = FocusRow.ItemArray[4].ToString();
                if (strType == "OUTLOOK")
                {
                    try
                    {
                        Email.Application oApp = new Email.Application();
                        Email._MailItem oMailItem = (Email._MailItem)oApp.CreateItemFromTemplate(strPath, Type.Missing);
                        //oMailItem.Subject = "abc";

                        oMailItem.Display(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "WORD")
                {
                    try
                    {
                        Word.Application wordApp;
                        Word.Document doc;
                        wordApp = new Word.ApplicationClass();
                        wordApp.Visible = true;
                        object fileName = strPath;
                        object missing = Type.Missing;
                        object fReadOnly = false;
                        doc = wordApp.Documents.Open(ref fileName,
                            ref missing, ref fReadOnly, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing, ref missing);
                        //doc.Activate();

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "EXCEL")
                {
                    try
                    {
                        Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
                        Excel.Workbook workBook = oExcel.Workbooks.Open(strPath, 0, true, 5, null, null, true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, null, null);
                        //Excel.Worksheet ws = (Excel.Worksheet)oExcel.ActiveSheet;
                        //ws.Activate();
                        //ws.get_Range("A1", "IV65536").Font.Size = 8;
                        oExcel.Visible = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "PDF")
                {
                    ACMS.ACMSStaff.To_Do_List.frmPDFviewer frm = new frmPDFviewer(strPath);
                    frm.Show();
                }
                else if (strType == "VIDEO")
                {
                    frmVideoPlayer frmPlayer = new frmVideoPlayer(strPath);
                    frmPlayer.Show();
                }
            }
            else if (gridView1.FocusedRowHandle >= 0)
            {
                FocusRow = gridView1.GetDataRow(gridView1.FocusedRowHandle);
                string strType = FocusRow.ItemArray[3].ToString();
                string strPath = FocusRow.ItemArray[4].ToString();
                //ACMS.ACMSStaff.WorkFlow.MyCustomEditForm frm = new ACMS.ACMSStaff.WorkFlow.MyCustomEditForm((int)FocusRow.ItemArray[0], oUser.NDepartmentID());
                //frm.Show();
            }
        }
Пример #25
0
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi =
                gridView1.CalcHitInfo((sender as System.Windows.Forms.Control).PointToClient(System.Windows.Forms.Control.MousePosition));
            DataRow FocusRow;

            if (hi.RowHandle >= 0)
            {
                FocusRow = gridView1.GetDataRow(hi.RowHandle);
                string strType = FocusRow.ItemArray[3].ToString();
                string strPath = FocusRow.ItemArray[4].ToString();
                if (strType == "OUTLOOK")
                {
                    try
                    {
                        Email.Application oApp      = new Email.Application();
                        Email._MailItem   oMailItem = (Email._MailItem)oApp.CreateItemFromTemplate(strPath, Type.Missing);
                        //oMailItem.Subject = "abc";

                        oMailItem.Display(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "WORD")
                {
                    try
                    {
                        Word.Application wordApp;
                        Word.Document    doc;
                        wordApp         = new Word.ApplicationClass();
                        wordApp.Visible = true;
                        object fileName  = strPath;
                        object missing   = Type.Missing;
                        object fReadOnly = false;
                        doc = wordApp.Documents.Open(ref fileName,
                                                     ref missing, ref fReadOnly, ref missing, ref missing, ref missing,
                                                     ref missing, ref missing, ref missing, ref missing, ref missing,
                                                     ref missing, ref missing, ref missing, ref missing, ref missing);
                        //doc.Activate();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "EXCEL")
                {
                    try
                    {
                        Excel.ApplicationClass oExcel   = new Excel.ApplicationClass();
                        Excel.Workbook         workBook = oExcel.Workbooks.Open(strPath, 0, true, 5, null, null, true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, null, null);
                        //Excel.Worksheet ws = (Excel.Worksheet)oExcel.ActiveSheet;
                        //ws.Activate();
                        //ws.get_Range("A1", "IV65536").Font.Size = 8;
                        oExcel.Visible = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (strType == "PDF")
                {
                    ACMS.ACMSStaff.To_Do_List.frmPDFviewer frm = new ACMS.ACMSStaff.To_Do_List.frmPDFviewer(strPath);
                    frm.Show();
                }
                else if (strType == "VIDEO")
                {
                    ACMS.ACMSStaff.To_Do_List.frmVideoPlayer frmPlayer = new ACMS.ACMSStaff.To_Do_List.frmVideoPlayer(strPath);
                    frmPlayer.Show();
                }
            }
            else if (gridView1.FocusedRowHandle >= 0)
            {
                FocusRow = gridView1.GetDataRow(gridView1.FocusedRowHandle);
                string strType = FocusRow.ItemArray[3].ToString();
                string strPath = FocusRow.ItemArray[4].ToString();
                //ACMS.ACMSStaff.WorkFlow.MyCustomEditForm frm = new ACMS.ACMSStaff.WorkFlow.MyCustomEditForm((int)FocusRow.ItemArray[0], oUser.NDepartmentID());
                //frm.Show();
            }
        }
Пример #26
0
        void buttonSendForReview_Click(object sender, EventArgs e)
        {
            UsageMetrics.IncrementUsage(UsageMetrics.UsageKind.CommitToolComposeReviewRequestEMail);

            var subject = GetReviewRequestSubject();

            var body = GetHtmlReviewRequestBody();

            var app = new Outlook.Application();

            Outlook.MailItem msg;
            if (!string.IsNullOrWhiteSpace(Settings.Default.ReviewRequestTemplate))
            {
                msg = (Outlook.MailItem)app.CreateItemFromTemplate(Settings.Default.ReviewRequestTemplate);

                // make subject
                if(string.IsNullOrWhiteSpace(msg.Subject))
                    msg.Subject = subject;
                else if (msg.Subject.Contains("$$SUBJECT$$"))
                    msg.Subject = msg.Subject.Replace("$$SUBJECT$$", subject);
                else if (msg.Subject.Contains("$$NOSUBJECT$$"))
                    msg.Subject = msg.Subject.Replace("$$NOSUBJECT$$", "");
                else
                    msg.Subject = msg.Subject + " " + subject;

                msg.HTMLBody = BuildMailBody(body, msg.HTMLBody);
            }
            else
            {
                msg = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
                msg.Subject = subject;
                msg.HTMLBody = BuildMailBody(body);
            }

            var r = comboBoxReviewer.SelectedItem as MailAddress;
            if(r != null)
                msg.To = r.Address;

            msg.Display();
        }
Пример #27
0
 public void SendAgain(Office.IRibbonControl control)
 {
     try
     {
         int counter = 0;
         int check1  = 0;
         foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
         {
             check1++;
         }
         if (check1 == 1)
         {
             foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
             {
                 //DZIAŁA MIMO IŻ NIE POWINNO XD
                 if (counter == 0)
                 {
                     if (email != null)
                     {
                         check(email);
                         if (checkIfTemplateWasSend)
                         {
                             /*MessageBox.Show("ODSYŁAMY automatycznie bo chamy niemyte nie czytajoXD");*/
                             string[]     tab        = pathForTemplate.Split('\\');
                             string       nazwaPliku = tab[tab.Length - 1];
                             DialogResult result     = MessageBox.Show("Do you want to send template once again? \nTemplate name: " + nazwaPliku + "\nOn mail: " + email.Subject + ",\n\n" + Tools.ShowAllReceivers(), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                             if (result == DialogResult.Yes)
                             {
                                 Outlook.Application oApp         = new Outlook.Application();
                                 MailItem            emailToReply = oApp.CreateItemFromTemplate(pathForTemplate) as MailItem;
                                 emailToReply.Subject = "RE: " + email.Subject;
                                 emailToReply.To      = email.ReplyAll().To;
                                 if (email != null)
                                 {
                                     Outlook.MailItem replyMail = email.Reply();
                                     replyMail.HTMLBody = emailToReply.HTMLBody + replyMail.HTMLBody;
                                     replyMail.To       = email.ReplyAll().To;
                                     replyMail.Send();
                                 }
                             }
                         }
                         else
                         {
                             MessageBox.Show("First you should send template.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Mail is null.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
                 else
                 {
                     MessageBox.Show("You choose more than one mail", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 counter++;
             }
         }
         else
         {
             MessageBox.Show("You choose more than one mail", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     } catch (Exception e)
     {
         MessageBox.Show("Exception in Send Again: \n" + e.Message);
     }
     checkIfFitToTemplate   = false;
     checkIfTemplateWasSend = false;
 }
Пример #28
0
        void GetClipboardData()
        {
            try
            {
                IDataObject iData = new DataObject();
                iData = Clipboard.GetDataObject();

                if (iData.GetDataPresent(DataFormats.Text))
                {
                    //Enable if need to see text...
                    //txtMain.Text = (string)iData.GetData(DataFormats.Text);


                    string t = (string)iData.GetData(DataFormats.Text);
                    if (t.IndexOf(keyword) == 0)
                    {
                        //we get the clean url
                        t = GetURL(t);

                        IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, rdp.MainWindowTitle);

                        ShowWindow(hwnd, SW_MINIMIZE);
                        Process.Start(t);
                    }
                    else if (t.IndexOf(mkeyword) == 0)
                    {
                        //we process that string into an object
                        MailInfo mInfo = new MailInfo(t);

                        IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, rdp.MainWindowTitle);

                        //minimize rdp
                        ShowWindow(hwnd, SW_MINIMIZE);

                        //OUTLOOK PROCESS HERE!
                        //we load the template path
                        string template = CMSettings.Default.TemplateLocation;

                        //here we create an Outlook App instance to create a new mailitem from template
                        Outlook.Application oApp  = new Outlook.Application();
                        Outlook.MailItem    nMail = oApp.CreateItemFromTemplate(template) as Outlook.MailItem;
                        //Outlook.MailItem nMail = oApp.CreateItemFromTemplate(@"C:\Users\Alex Castro\AppData\Roaming\Microsoft\Templates\Ticket Request.oft") as Outlook.MailItem;

                        nMail.To = mInfo.Email;

                        //after assigning the email to the "To" bit, we open
                        //a word document to edit the body. Why a word doc?
                        //Because we lose the template formatting otherwise!
                        Word.Document doc = new Word.Document();
                        doc = nMail.GetInspector.WordEditor as Word.Document;
                        Word.Range fRng = doc.Range();

                        while (fRng.Find.Execute(FindText: "…,"))
                        {
                            fRng.Text = $"{mInfo.Name},";
                            fRng.Collapse(0);
                        }
                        while (fRng.Find.Execute(FindText: "* … *"))
                        {
                            fRng.Text = $"* {mInfo.ID} *";
                            fRng.Collapse(0);
                        }

                        nMail.Display();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #29
0
 public OutlookInterop()
 {
     OutlookApp = new Outlook.Application();
     MailItem   = OutlookApp.CreateItemFromTemplate(
         @"c:\GilCats\Autoemail\Templates\default.oft", Type.Missing) as Outlook.MailItem;
 }
Пример #30
0
        public static List <printumBestellPositionen> createNewEmailmitAnhang(string pfad, string bestellnr, int _projektnr, string email)
        {
            projektnr = _projektnr;

            pdfPfad  = pfad.Substring(0, pfad.Length - 4) + @".pdf";
            mailPfad = pfad.Substring(0, pfad.Length - 4) + @".msg";
            string mailtemplate = @"\\192.168.26.250\PT-99-Vorl\Dokumente\BestellungsMail-Template.oft";

            Excel.Application excelApp      = new Excel.Application();
            Excel.Workbook    excelWorkbook = excelApp.Workbooks.Open(pfad);

            // Zeilen auslesen und in die Datenbank schreiben.
            bestellliste = ExcelHelper.getBestellPositionen(excelWorkbook, bestellnr);

            excelWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, pdfPfad);



            excelWorkbook.Close(false, pfad, null);
            excelApp.Quit();
            Marshal.ReleaseComObject(excelWorkbook);
            Marshal.ReleaseComObject(excelApp);


            Outlook.Application app = new Outlook.Application();


            Outlook.Folder folder = app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
            dieMail = app.CreateItemFromTemplate(mailtemplate, folder) as Outlook.MailItem;
            Outlook.Inspector mailInspector = dieMail.GetInspector;
            mailInspector.Activate();

            dieMail.Subject = "PT-PRINTUM Bestellung  " + bestellnr + "  Projekt: " + projektnr.ToString();

            dieMail.To = email;

            dieMail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

            //var textt = dieMail.HTMLBody;
            //textt.Replace(@"</body>", @"<b>Hinweis</b>:" +
            //                @"Bitte geben Sie immer unsere kompletten Bestelldaten(Printum Auftrags Nr.und Bestell Nr.) auf allen" +
            //                @"Schriftstücken zum Auftrag(Auftragsbestätigung, Lieferschein und Rechnung) vollständig an!" +
            //                @"Fehlende oder unvollständige Bestelldaten können ansonsten ggf. zu einem verzögertem Zahlungsausgleich führen. </body>");

            //dieMail.HTMLBody = textt;
            dieMail.Attachments.Add(
                pdfPfad,
                Outlook.OlAttachmentType.olByValue,
                1,
                "PT-PRINTUM Bestellung  " + bestellnr);

            dieMail.Display(true);
            Form4_Spinner f4 = (Application.OpenForms["Form4_Spinner"] as Form4_Spinner);

            if (f4 != null)
            {
                f4.Close();
            }

            ((Outlook.ItemEvents_10_Event)dieMail).Send += ThisMai_send;

            return(bestellliste);
        }