コード例 #1
0
ファイル: cEmail.cs プロジェクト: rafaelcolvara/NavEventos
        public void Monta(int pIdEvento, string pAssunto)
        {
            lock (cGlobal.bloqueadorThread)
            {
                int idTipoEvento             = 0;
                previa_Cronograma pc         = new previa_Cronograma();
                Outlook._MailItem oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector oInspector = oMailItem.GetInspector;

                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;

                using (DataSet dsmsg = pc.retorna_mensagem_email(pIdEvento))
                {
                    oMailItem.Subject = dsmsg.Tables["MsgEmail"].Rows[0]["Mensagem"].ToString();
                    idTipoEvento      = Convert.ToInt32(dsmsg.Tables["MsgEmail"].Rows[0]["ID_TIPO_EVENTO"].ToString());
                }

                #region MONTA CORPO DO E-MAIL
                pAssunto      += oMailItem.Subject;
                oMailItem.Body = pAssunto;

                #endregion

                oMailItem.Display(true);

                if (pc.exclui_mensagem_email(pIdEvento, idTipoEvento) < 1)
                {
                    throw new Exception("Não foi possivel atualizar mensagem. Atenção no formato do email");
                }
            }
        }
コード例 #2
0
 /*
  * Uses the email and opens an outlook window with subject, body, to address, and attachments
  * filled in.
  */
 public void openOutlookWindow()
 {
     try
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.To      = toAddress;
         oMailItem.Subject = subject;
         oMailItem.Body    = body;
         oMailItem.CC      = cc;
         if (attach1 != null)
         {
             oMailItem.Attachments.Add(attach1);
         }
         if (attach2 != null)
         {
             oMailItem.Attachments.Add(attach2);
         }
         oMailItem.Display(true);
         oApp.ActiveWindow();
     }catch (System.Exception ex)
     {
         MessageBox.Show("Outlook Error: " + ex.Message, "Error with outlook window", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Console.WriteLine("Error with outlook." + ex.Message);
     }
 }
コード例 #3
0
 protected void ButtonSendMail_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> lstAllRecipients = new List <string>();
         //Below is hardcoded - can be replaced with db data
         lstAllRecipients.Add("*****@*****.**");
         lstAllRecipients.Add("*****@*****.**");
         Outlook.Application outlookApp = new Outlook.Application();
         Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
         Outlook.Inspector   oInspector = oMailItem.GetInspector;
         // Thread.Sleep(10000);
         // Recipient
         Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
         foreach (String recipient in lstAllRecipients)
         {
             Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
             oRecip.Resolve();
         }
         //Add CC
         Outlook.Recipient oCCRecip = oRecips.Add("*****@*****.**");
         oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
         oCCRecip.Resolve();
         //Add Subject
         oMailItem.Subject = "Test Mail";
         // body, bcc etc...
         //Display the mailbox
         oMailItem.Display(true);
     }
     catch (Exception objEx)
     {
         Response.Write(objEx.ToString());
     }
 }
コード例 #4
0
        public static Boolean SendOutlookMail(string recipient, string subject, string body)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector   oInspector = oMailItem.GetInspector;

                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
                Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add(recipient);
                oRecip.Resolve();

                if (subject != "")
                {
                    oMailItem.Subject = subject;
                }
                if (body != "")
                {
                    oMailItem.Body = body;
                }
                oMailItem.Display(true);
                return(true);
            }
            catch (Exception objEx)
            {
                MessageBox.Show(objEx.ToString());
                return(false);
            }
        }
コード例 #5
0
        public void CreateEmail(DateTime time_period_start)
        {
            // Copy the excel sheet and rename properly
            var strCurrentFilePath     = Properties.Settings.Default.OutputDirectory + Properties.Settings.Default.OutputExcelFile;
            var file_type_dot_index    = Properties.Settings.Default.OutputExcelFile.LastIndexOf('.');
            var strOutputPathDirectory = Properties.Settings.Default.OutputDirectory;
            var strOutputPathFileName  = Properties.Settings.Default.Name + " - " +
                                         Properties.Settings.Default.OutputExcelFile.Substring(0, file_type_dot_index) + " (" +
                                         time_period_start.ToString(@"dd\-MM\-yy") + " - " +
                                         time_period_start.AddDays(14).ToString(@"dd\-MM\-yy") + ")" +
                                         Properties.Settings.Default.OutputExcelFile.Substring(file_type_dot_index);
            var strFullPath = strOutputPathDirectory + strOutputPathFileName;

            // Write data to excel spreadsheet
            XSSFWorkbook hssfwb;

            using (FileStream file = new FileStream(strCurrentFilePath, FileMode.Open, FileAccess.Read))
            {
                hssfwb = new XSSFWorkbook(file);
                file.Close();
            }

            using (FileStream file = new FileStream(strFullPath, FileMode.CreateNew, FileAccess.Write))
            {
                hssfwb.Write(file);
                file.Close();
            }

            // Create mail
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = Properties.Settings.Default.EmailRecipient;
            oMailItem.Subject = "Timesheet - " + Properties.Settings.Default.Name;
            var output_body = Properties.Settings.Default.EmailBody.Replace("*NAME*", Properties.Settings.Default.Name);

            output_body = output_body.Replace("*DATES*", time_period_start.ToShortDateString() + " - " + time_period_start.AddDays(14).ToShortDateString());
            oMailItem.Attachments.Add(strFullPath, Outlook.OlAttachmentType.olByValue, 1, "Timesheet");
            oMailItem.Body = output_body;
            oMailItem.Display(true);

            // Save / Store a copy in /saved folder
            if (Properties.Settings.Default.SaveLocalCopy)
            {
                strOutputPathDirectory = Properties.Settings.Default.OutputDirectory + "Saved\\";
                strFullPath            = strOutputPathDirectory + strOutputPathFileName;
                System.IO.Directory.CreateDirectory(strOutputPathDirectory);

                using (FileStream file = new FileStream(strFullPath, FileMode.CreateNew, FileAccess.Write))
                {
                    hssfwb.Write(file);
                    file.Close();
                }
            }

            // Delete
            File.Delete(strFullPath);
        }
コード例 #6
0
 private void btnContact_Click(object sender, EventArgs e)
 {
     Outlook.Application oApp      = new Outlook.Application();
     Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
     oMailItem.To = "*****@*****.**";
     oMailItem.CC = "*****@*****.**";
     // body, bcc etc...
     oMailItem.Display(true);
 }
コード例 #7
0
        private void btnEmail_Click(object sender, EventArgs e)
        {
            string body = "";
            List <RealTimePositionObject> AdrPositions   = new List <RealTimePositionObject>();
            List <RealTimePositionObject> HrdPositions   = new List <RealTimePositionObject>();
            List <RealTimePositionObject> OtherPositions = new List <RealTimePositionObject>();

            //generate the text
            LoadHeldUp();

            foreach (RealTimePositionObject r in HeldUpRealTimePositions)
            {
                //find positions with hedge data
                if (r.DtcActivity.Exists(d => d.ReasonCode == "260") || r.DtcActivity.Exists(d => d.ReasonCode == "261") ||
                    r.DtcActivity.Exists(d => d.ReasonCode == "270") || r.DtcActivity.Exists(d => d.ReasonCode == "271"))
                {
                    r.ContainsHedge = true;
                }

                if (r.TradeCategory.Contains("ADR"))
                {
                    AdrPositions.Add(r);
                }
                if (r.TradeCategory.Contains("HRD"))
                {
                    HrdPositions.Add(r);
                }
                if (!r.TradeCategory.Contains("HRD") && !r.TradeCategory.Contains("ADR"))
                {
                    OtherPositions.Add(r);
                }
            }

            AdrPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));
            HrdPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));
            OtherPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));

            body += "<br>ADR<br>";
            body += GenerateHtmlTable(AdrPositions);

            body += "<br>HRD<br>";
            body += GenerateHtmlTable(HrdPositions);

            body += "<br>OTHER<br>";
            body += GenerateHtmlTable(OtherPositions);

            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            oMailItem.To         = "";
            oMailItem.Subject    = "Held Up Positions";
            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
            oMailItem.HTMLBody   = body;

            oMailItem.Display(false);
        }
コード例 #8
0
ファイル: ReportMe.cs プロジェクト: Pezmet/ReportMe
        //format the email
        private void mailto_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            DateTime dt = DateTime.Now;

            oMailItem.To      = "*****@*****.**";
            oMailItem.CC      = "*****@*****.**";
            oMailItem.Subject = "[Report Me] " + String.Format("{0:d-mm-yyy}", dt);
            oMailItem.Display(false);
        }
コード例 #9
0
        //format the email
        private void mailto_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            DateTime dt = DateTime.Now;

            oMailItem.To      = "<<Email Here>>";
            oMailItem.CC      = "<<Email Here>>";
            oMailItem.Subject = "[Report Me] " + String.Format("{0:d-mm-yyy}", dt);
            oMailItem.Display(false);
        }
コード例 #10
0
        //sets up the mail item
        private void CreateMailItem()
        {
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = clientEmail;
            oMailItem.Subject = "Grenci CPA Invoice";

            List <string> attachments = new List <string>();

            oMailItem.Attachments.Add(@filePath);
            oMailItem.Display(true);
        }
コード例 #11
0
 public void Email(string email, string mail)
 {
     try
     {
         Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
         Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
         oMailItem.To   = email;
         oMailItem.Body = mail;
         oMailItem.Display(true);
     }
     catch { InformationBox.Show("Error saving Outlook contact", "Outlook Error"); }
 }
コード例 #12
0
        public static void SendEmail(dynamic json)
        {
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            String destEmail = "";
            String subject   = "";
            String body      = "";

            for (int i = 1; i < json.recognized.Count; i++)
            {
                String operation = json.recognized[i].ToString();
                Console.WriteLine(operation);

                switch (operation)
                {
                // destination addresses
                case "JOANA":
                    destEmail = "*****@*****.**";
                    break;

                case "DENIS":
                    destEmail = "*****@*****.**";
                    break;

                case "LEONARDO":
                    destEmail = "*****@*****.**";
                    break;

                // excuses
                case "LATE":
                    subject = "Estou atrasado";
                    body    = "Olá, estou um pouco atrasado. Peço desculpa.";
                    break;

                case "GOING":
                    subject = "Estou a caminho";
                    body    = "Olá, estou a caminho.";
                    break;

                case "CALL_LATER":
                    subject = "Ligo mais tarde";
                    body    = "Olá, ligo-te daqui a pouco.";
                    break;
                }
            }

            oMailItem.To      = destEmail;
            oMailItem.Subject = subject;
            oMailItem.Body    = body;

            oMailItem.Display(true);
        }
コード例 #13
0
 private void OnOpenOutlook(object sender, MouseButtonEventArgs e)
 {
     try
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.Body = txt_shareHyperlink.Text;
         oMailItem.Display(true);
     }
     catch (Exception)
     {
     }
 }
コード例 #14
0
        internal void SendExceptionEmail(string subject, string userName, string exceptionInfo)
        {
            if (!OfficeAppShortcuts.CheckOutlookExists())
            {
                MessageBox.Show("Error. Unable to detect Outlook, please install Outlook before attempting to send a bug report.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

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

            if (dialogIsAlreadyRunning == true)
            {
                MessageBox.Show("An Outlook window is already open to send a bug report.\n\nPlease send or close the current Outlook window " +
                                "in order to send this report.", "Unable to send bug report", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            dialogIsAlreadyRunning = true;

            DialogResult dialogresult = MessageBox.Show($"An error has occurred. Do you wish to send a bug report?", "An error has occurred!",
                                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

            if (dialogresult == DialogResult.Yes)
            {
                Outlook._MailItem MailItem = (Outlook._MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

                MailItem.To       = "*****@*****.**";
                MailItem.Subject  = subject;
                MailItem.HTMLBody = $"<html><body> The user <strong>{userName}</strong> has reported the following exception error: <br><br> {exceptionInfo} </body></html>";
                try
                {
                    MailItem.Display(true);
                } catch
                {
                    // add error here for if dialog box is already open.
                    Marshal.ReleaseComObject(outlook);
                    Marshal.ReleaseComObject(MailItem);
                    dialogIsAlreadyRunning = false;
                }

                Marshal.ReleaseComObject(outlook);
                Marshal.ReleaseComObject(MailItem);
            }

            dialogIsAlreadyRunning = false;

            Technical_Support_Control_Panel.Call_Recordings_Form ResetSettings = new Technical_Support_Control_Panel.Call_Recordings_Form();

            ResetSettings.ResetComboBoxSettings();
        }
コード例 #15
0
 private void SaveOpenEmailCommand()
 {
     try
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.To = GlobalConstants.COMPANY_MAIL_ADDRESS;
         oMailItem.Display(true);
     }
     catch (Exception e)
     {
         LogHandler.WriteLog(e.ToString(), LogLevel.WARNING);
     }
 }
コード例 #16
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (textBox5.Text == "")
     {
         MessageBox.Show("You didn't give an email address");
     }
     else
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.To = textBox5.Text;
         oMailItem.Display(true);
     }
 }
コード例 #17
0
        private void CreateMailItem()
        {
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = "*****@*****.**";
            oMailItem.Subject = "Grenci CPA Invoice";

            List <string> attachments = new List <string>();

            attachments.Add(@"C:\Users\hoffmanw\Documents\Tests\test.txt");

            oMailItem.Attachments.Add(attachments[0]);
            oMailItem.Display(true);
        }
コード例 #18
0
 public void SendTestMail(string EmailUrl)
 {
     try
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.To = EmailUrl;
         // body, bcc etc...
         oMailItem.Display(true);
     }
     catch (Exception e)
     {
         Console.WriteLine("{0} Exception caught: ", e);
     }
 }
コード例 #19
0
        private void btnSendEmail_Click(object sender, RoutedEventArgs e)
        {
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            //oMailItem.To = "*****@*****.**";
            oMailItem.To = "*****@*****.**";

            oMailItem.Subject    = "Hedge Cash Forecasting";
            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

            string htmlbody = CreateHTMLBody();

            oMailItem.HTMLBody = htmlbody;

            oMailItem.Display(false);
        }
コード例 #20
0
        public void HandleReplyWithTemplate(JiraTemplate jiraTemplate)
        {
            if (dataModel.JiraEmail == null || dataModel.JiraEmail.Length < 1)
            {
                MessageBox.Show("Invalid Jira Email.\nPlease update email address in Jira Tab.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (jiraTemplate == null)
            {
                // fallback to default
                jiraTemplate = dataModel.DefaultTemplate;
            }

            try
            {
                Outlook._Explorer exp = Globals.ThisAddIn.Application.ActiveExplorer();
                if (exp != null && exp.Selection != null && exp.Selection.Count > 0)
                {
                    foreach (Object item in exp.Selection)
                    {
                        if (item is Outlook._MailItem)
                        {
                            Outlook._MailItem mailItem = (item as Outlook._MailItem);
                            Outlook._MailItem reply    = mailItem.ReplyAll();

                            AddTemplateDataToMailItem(reply, jiraTemplate);
                            reply.Display();
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                // To see this exception: Click on the email folders tree's top node i.e. the one which shows like a startup page
                // and contains Calendar information, tasks and messages overview. After that from ribbon click on the reply button.
                // http://stackoverflow.com/questions/17211827/how-to-check-if-a-vsto-outlook-explorer-object-has-been-closed
                // Ex.Message = "The Explorer has been closed and cannot be used for further operations. Review your code and restart Outlook."
                // Outlook gives valid explorer but selection paramter generates exception.
                //MessageBox.Show(Ex.Message + "\n" + Ex.StackTrace, "Error!!!");
                RegistryOperation.CreateBinaryKeyValue(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNameLastError,
                                                       Ex.Message.ToString() + "\n" + Ex.StackTrace.ToString());
            }
        }
コード例 #21
0
        private void PrepareMail(string mail, string department, string subject, string body)
        {
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);


            if (mail.Contains(","))
            {
                mail = mail.Replace(",", ";"); //convert to semicolon format for multiple receipients
            }

            oMailItem.To      = mail;
            oMailItem.Subject = subject.Replace("$DEPARTMENT", department);
            oMailItem.Body    = body.Replace("$DEPARTMENT", department);
            string path = Directory.GetCurrentDirectory();

            oMailItem.Attachments.Add(path + "/" + department + ".pptx");
            oMailItem.Display(false);
        }
コード例 #22
0
        public bool EnviarEmail()
        {
            try
            {
                List <string> listaEmail = new List <string>();
                listaEmail.Add(ConfigurationManager.AppSettings["EmailGerente"].ToString());

                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector   oInspector = oMailItem.GetInspector;
                Outlook.Recipients  oRecips    = (Outlook.Recipients)oMailItem.Recipients;
                foreach (String recipient in listaEmail)
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
                    oRecip.Resolve();
                }

                //Add CC
                //Outlook.Recipient oCCRecip = oRecips.Add("*****@*****.**");
                //oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                //oCCRecip.Resolve();

                //Add Assunto
                oMailItem.Subject = "View de consulta ao Trello Atualizada (Mensagem automática).";

                StringBuilder strEmail = new StringBuilder();
                strEmail.Append("<html>");
                strEmail.AppendFormat("Olá Sr(a). {0}, {1}", ConfigurationManager.AppSettings["NomeGerente"].ToString(), Environment.NewLine);
                strEmail.AppendFormat("A base de consulta ao Trello foi atualizada em: {0} e está disponível para consultas.", DateTime.Now);
                strEmail.Append("</html>");

                oMailItem.HTMLBody = strEmail.ToString();
                oMailItem.Display(true);
                return(true);
            }
            catch (Exception objEx)
            {
                Console.Write(objEx.ToString());
                return(false);
            }
        }
コード例 #23
0
ファイル: TravelyseDialog.cs プロジェクト: pavi1286/Osler
        private void CopyToClipboard()
        {
            // Load the webpage into a WebBrowser control
            WebBrowser wb = new WebBrowser();

            wb.ScrollBarsEnabled      = false;
            wb.ScriptErrorsSuppressed = true;
            wb.Navigate("https://app.powerbi.com/view?r=eyJrIjoiYmJlMTk5ZjItY2M3MS00ODE1LWIwODItNTkwNDc4YjVlZjZlIiwidCI6ImM0OWEyMzk1LWQxNTMtNDljYy04MjA4LTAyMjQyNzQ1ZWYyMSIsImMiOjh9");
            System.Threading.Thread.Sleep(10000);

            while (wb.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }

            wb.Width  = wb.Document.Body.ScrollRectangle.Width;
            wb.Height = wb.Document.Body.ScrollRectangle.Height;

            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);

            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();

            var stream = new MemoryStream();

            bitmap.Save(@"C:\Users\admin\Pictures\Test\TestFilename.PNG", ImageFormat.Png);
            stream.Position = 0;

            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = "*****@*****.**";
            oMailItem.Subject = "Test";


            //oMailItem.Attachments.Add(new System.Net.Mail.Attachment(stream, "image/jpg"));
            // oMailItem.Attachments.Add(new System.Net.Mail.Attachment(stream, "image/jpg"));
            oMailItem.Attachments.Add(new System.Net.Mail.Attachment(@"C:\Users\admin\Pictures\Test\TestFilename.PNG"));

            oMailItem.Display(true);
        }
コード例 #24
0
ファイル: OutlookHelper.cs プロジェクト: bacca87/great2
        public static bool NewMessage(EmailMessageDTO message)
        {
            try
            {
                Outlook.Application outlook = new Outlook.Application();
                Outlook._MailItem   email   = (Outlook._MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

                foreach (string address in message.ToRecipients)
                {
                    Outlook.Recipient recipient = email.Recipients.Add(address);
                    recipient.Type = (int)Outlook.OlMailRecipientType.olTo;
                    recipient.Resolve();
                }

                foreach (string address in message.CcRecipients)
                {
                    Outlook.Recipient recipient = email.Recipients.Add(address);
                    recipient.Type = (int)Outlook.OlMailRecipientType.olCC;
                    recipient.Resolve();
                }

                email.Subject = message.Subject;
                email.Body    = message.Body;

                foreach (string attachment in message.Attachments)
                {
                    email.Attachments.Add(attachment, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                }

                email.Display(false);
            }
            catch (Exception ex)
            {
                Debugger.Break();
                return(false);
            }

            return(true);
        }
コード例 #25
0
        private void OpenOutlook()
        {
            try {
                Outlook.Application application = new Outlook.Application();
                Outlook._MailItem   mailItem    = (Outlook._MailItem)application.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.To      = ConfigurationManager.AppSettings["To"];
                mailItem.CC      = ConfigurationManager.AppSettings["CC"];
                mailItem.Subject = "WFH - " + Date.Value.ToString("dd-MMM-yyyy");

                var body = "Time In: " + TimeIn.Value.ToString("hh:mm tt").ToUpper() + Environment.NewLine;
                body += "Time Out: " + TimeOut.Value.ToString("hh:mm tt").ToUpper() + Environment.NewLine;
                body += "Hours: " + Hours.Value + Environment.NewLine;
                body += "Employee Code: " + EmployeeCode.Text;

                mailItem.Body = body;
                mailItem.Display(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Outlook Interop Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #26
0
        private void button3_Click(object sender, EventArgs e)
        {
            Form2 RForm = new Form2();

            RForm.ShowDialog();
            if (RForm.DialogResult != DialogResult.OK)
            {
                RForm.Dispose();

                return;
            }
            try
            {
                Object display             = true;
                Outlook._Application olook = new Outlook.Application();
                Outlook._MailItem    omail = olook.CreateItem(0);
                omail.HTMLBody = createMailBody(RForm.ReportCBX.Text);
                omail.Display(display);
            }
            finally
            {
                RForm.Dispose();
            }
        }
コード例 #27
0
        private void SendWorkEmail()
        {
            try
            {
                //Get email content
                var cFileName   = Helper.GetAppSettingValue("TaskFileLocation");
                var mailContent = new StringBuilder();

                var content = System.IO.File.ReadAllLines(cFileName);

                mailContent.Append(@"<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40""><head><meta http-equiv=Content-Type content=""text/html; charset=us-ascii""><meta name=Generator content=""Microsoft Word 15 (filtered medium)""><style><!--
/* Font Definitions */
@font-face
	{font-family:""Cambria Math"";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Verdana;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:""Calibri"",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	font-size:12.0pt;
	font-family:""Times New Roman"",serif;}
span.EmailStyle18
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:windowtext;}
span.EmailStyle19
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
span.EmailStyle20
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
span.EmailStyle21
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
span.EmailStyle22
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
span.EmailStyle23
	{mso-style-type:personal;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
span.EmailStyle24
	{mso-style-type:personal-reply;
	font-family:""Calibri"",sans-serif;
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=""edit"" spidmax=""1026"" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=""edit"">
<o:idmap v:ext=""edit"" data=""1"" />
</o:shapelayout></xml><![endif]--></head>
<body lang=EN-US link=""#0563C1"" vlink=""#954F72""><div class=WordSection1><p class=MsoNormal>Hi<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>Following is my today&#8217;s work report.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p>
<table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'>
");

                foreach (var itmWorkItem in content)
                {
                    if (itmWorkItem.Trim() != "")
                    {
                        var cSplitted = itmWorkItem.Trim().Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);

                        string cProjectName = "";
                        string cWorkDesc    = "";

                        if (cSplitted.Length > 1)
                        {
                            cProjectName = cSplitted[0].Trim();
                            cWorkDesc    = cSplitted[1].Trim();
                        }
                        else
                        {
                            cWorkDesc = cSplitted[0].Trim();
                        }

                        mailContent.AppendFormat(@"<tr style='height:15.95pt'><td width=197 valign=top style='width:148.1pt;border:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:15.95pt'><p class=MsoNormal><b>
{0}
<o:p></o:p></b></p></td><td width=569 valign=top style='width:426.65pt;border:solid windowtext 1.0pt;border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.95pt'><p class=MsoNormal><span style='color:#1F497D'>
{1}
<o:p></o:p></span></p></td></tr>", cProjectName, cWorkDesc);
                    }
                }

                mailContent.Append(@" </table>
<p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='font-size:8.0pt;font-family:""Arial"",sans-serif;color:black'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:8.0pt;font-family:""Arial"",sans-serif;color:black'>Thanks &amp; Regards,</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:""Verdana"",sans-serif;color:#333333'>&nbsp;</span></b><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:""Verdana"",sans-serif;color:#333333'>Your Name</span></b><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><b><span style='font-size:7.0pt;font-family:""Verdana"",sans-serif;color:#595959'>Your Designation</span></b><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:""Verdana"",sans-serif;color:#5B8F22'>Company Name</span></b><span style='font-size:10.0pt;color:black'>| </span><a href=""mailto:emailAddress"" target=""_blank""><span style='font-size:10.0pt'>[email protected]</span></a><span style='font-size:10.0pt;color:#1F497D'> </span><span style='font-size:10.0pt;color:black'>|</span><span style='color:black'> </span><a href=""http://www.yourcompanyName.here/"" target=""_blank""><span style='font-size:10.0pt'>www.yourCompanyName.here</span></a><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.0pt;color:#A6A6A6'>NOTICE: The contents of this message, together with any attachments, are intended only for the use of the person(s) to which they are addressed and may contain confidential and/or privileged information. Further, any medical information herein is confidential and protected by law. It is unlawful for unauthorized persons to use, review, copy, disclose, or disseminate confidential medical information. If you are not the intended recipient, immediately advise the sender and delete this message and any attachments. Any distribution, or copying of this message, or any attachment, is prohibited.</span><o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>");


                //Start configuring mail
                Outlook.Application oApp      = new Outlook.Application();
                Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                oMailItem.To = Helper.GetAppSettingValue("MailTo");
                oMailItem.CC = Helper.GetAppSettingValue("MailToCC");

                oMailItem.Subject = string.Format("Work Report: {0}", DateTime.Now.ToString("dd-MMMM-yyyy"));

                oMailItem.HTMLBody = mailContent.ToString();

                // body, bcc etc...
                oMailItem.Display(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #28
0
ファイル: MyCustomEditForm.cs プロジェクト: kimykunjun/test
        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();
            }
        }
コード例 #29
0
        private void btnSendEMail_Click(object sender, EventArgs e)
        {
            string strBody = "";

            strBody = txtBody.Text.Replace("\r\n", "<br />");
            string strSignature = ReadSignature();

            strBody = strBody + "<br /><br />" + strSignature;

            Outlook.Application oApp = new Outlook.Application();
            // Create a new mail item.

            Outlook._MailItem oMsg = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMsg.HTMLBody  = "<FONT face=\"Arial\">";
            oMsg.HTMLBody += strBody;
            //Add an attachment.
            oMsg.Attachments.Add(lnkReport.Text);
            //Subject line
            oMsg.Subject = txtSubject.Text;
            // Add a recipient.
            Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

            string[] EMAddresses = txtTo.Text.Split(";,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < EMAddresses.Length; i++)
            {
                if (EMAddresses[i].Trim() != "")
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(EMAddresses[i]);
                    oRecip.Resolve();
                }
            }

            oMsg.CC = txtCC.Text;

            //oMsg.Display();

            //Send.
            //oMsg.Send(); //error here
            //((Outlook._MailItem)oMsg).Send(); -- this works
            oMsg.Display();

            // Clean up.
            //oRecip = null;
            oRecips = null;
            oMsg    = null;
            oApp    = null;

            if (txtDateEMailed.Text == "")
            {
                //UPDATE EMAIL DATE
                SqlConnection sqlcnn = GISClass.DBConnection.GISConnection();
                if (sqlcnn == null)
                {
                    MessageBox.Show("Connection problems encountered." + Environment.NewLine + "Please contact your administrator.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                SqlCommand sqlcmd = new SqlCommand();
                sqlcnn = GISClass.DBConnection.GISConnection();
                if (sqlcnn == null)
                {
                    MessageBox.Show("Connection problems encountered." + Environment.NewLine + "Please contact your administrator.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                sqlcmd = new SqlCommand("UPDATE FinalRptRev SET DateEMailed = GetDate(), EMailedByID=" + LogIn.nUserID + " " +
                                        "WHERE ReportNo=" + nRptNo.ToString() + " AND RevisionNo=0", sqlcnn);
                sqlcmd.ExecuteNonQuery();
                sqlcmd.Dispose();
                sqlcnn.Close(); sqlcnn.Dispose();
            }
        }
コード例 #30
0
        // basic template function to send mail to specific customer
        private static void sendMail(MailDetails mailDetails)
        {
            OutlookInterop._MailItem  oMailItem  = null;
            OutlookInterop.Attachment attachment = null;
            string bodyMsg           = string.Empty;
            string signatureName     = SIGNATURE_LOGO_NAME;
            string signatureFilePath = Path.Combine(Directory.GetCurrentDirectory(), signatureName);
            string tempMsg           = string.Empty;

            // generate logo file from embedded resource (image)
            if (File.Exists(signatureFilePath) == false)
            {
                ImageConverter converter   = new ImageConverter();
                byte[]         tempByteArr = (byte[])converter.ConvertTo(Anko.Properties.Resources.logo, typeof(byte[]));
                File.WriteAllBytes(signatureFilePath, tempByteArr);
            }

            // outlook can be null in the first time
            if (outlookApp == null)
            {
                init();
            }

            try
            {
                // initiate outlook parameters
                oMailItem = (OutlookInterop._MailItem)outlookApp.CreateItem(OutlookInterop.OlItemType.olMailItem);
            }
            catch (Exception e)
            {
                OrdersParser._Form.log(string.Format("Failed to create mail. Error: {0}", e.Message), OrdersParser.LogLevel.Error);
                dispose();
                return;
            }

            OutlookInterop.Recipient  mailTo;
            OutlookInterop.Recipient  mailCc;
            OutlookInterop.Recipients toList = oMailItem.Recipients;
            OutlookInterop.Recipients ccList = oMailItem.Recipients;

            // TO
            foreach (String recipient in mailDetails.mailRecepient.to)
            {
                mailTo      = toList.Add(recipient);
                mailTo.Type = (int)OutlookInterop.OlMailRecipientType.olTo;
                mailTo.Resolve();
            }

            // CC
            foreach (String recipient in mailDetails.mailRecepient.cc)
            {
                mailCc      = ccList.Add(recipient);
                mailCc.Type = (int)OutlookInterop.OlMailRecipientType.olCC;
                mailCc.Resolve();
            }

            // add Subject
            oMailItem.Subject = mailDetails.subject;

            // add attachment excel file
            foreach (string filePath in mailDetails.attachments)
            {
                oMailItem.Attachments.Add(filePath,
                                          OutlookInterop.OlAttachmentType.olByValue,
                                          1,
                                          Path.GetFileName(filePath));
            }

            // verify that signature file exists
            if (File.Exists(signatureFilePath) == true)
            {
                // prepare body
                attachment = oMailItem.Attachments.Add(signatureFilePath,
                                                       OutlookInterop.OlAttachmentType.olEmbeddeditem,
                                                       null,
                                                       string.Empty);

                attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", signatureName);
            }
            else
            {
                OrdersParser._Form.log(string.Format("Cannot find signature logo in {0}", signatureFilePath), OrdersParser.LogLevel.Error);
            }

            bodyMsg += addHtmlPreffix();

            // message (based on templates from mailType)
            bodyMsg += addMailBodyMsg(mailDetails.mailType, mailDetails.bodyParameters);

            // signature
            bodyMsg += addMailSignature(signatureName);

            oMailItem.BodyFormat = OutlookInterop.OlBodyFormat.olFormatHTML;
            oMailItem.HTMLBody   = bodyMsg;

            // mark as high importance
            if (mailDetails.bHighImportance)
            {
                oMailItem.Importance = OutlookInterop.OlImportance.olImportanceHigh;
            }

            // async - display mail and proceed
            oMailItem.Display(false);
        }