Exemple #1
0
        public void Button_Click(Office.IRibbonControl control)
        {
            try
            {
                Outlook.Recipient  recipient  = null;
                Outlook.Recipients recipients = null;

                Outlook.Application application = new Outlook.Application();
                Outlook.Explorer    explorer    = application.ActiveExplorer();
                Outlook.Inspector   inspector   = application.ActiveInspector();
                inspector.Activate();
                Outlook._MailItem mailItem = inspector.CurrentItem;

                //Outlook.Application outlookApplication = new Outlook.Application();
                //Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem;

                if (mailItem != null)
                {
                    recipients = mailItem.Recipients;
                    recipients.ResolveAll();
                    String       StrR            = "";
                    const string PR_SMTP_ADDRESS =
                        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
                    foreach (Outlook.Recipient recip in recipients)
                    {
                        Outlook.PropertyAccessor pa = recip.PropertyAccessor;
                        string smtpAddress          =
                            pa.GetProperty(PR_SMTP_ADDRESS).ToString();

                        string[] strsplit = smtpAddress.Split('@');
                        if (!StrR.Contains(strsplit[1]))
                        {
                            StrR += strsplit[1] + Environment.NewLine;
                        }
                    }
                    if (StrR != string.Empty)
                    {
                        MyMessageBox ObjMyMessageBox = new MyMessageBox();
                        ObjMyMessageBox.ShowBox(StrR);
                    }



                    //recipient.Resolve();
                    //                DialogResult result = MessageBox.Show("Are you sure you want to send emails to the following domains " + StrR, "Varify Domains ",
                    //MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    //                if (result == DialogResult.Yes)
                    //                {
                    //                    //code for Yes
                    //                }
                    //                else
                    //                {

                    //                }
                }
            }
            catch (Exception ex)
            {
            }
        }
 public override void Activate()
 {
     inspector.Activate();
 }
Exemple #3
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);
        }