예제 #1
0
 public static void CreateMail(string fileName, string link)
 {
     try
     {
         var application = new MsOutlook.ApplicationClass();
         var mailItem = application.CreateItem(MsOutlook.OlItemType.olMailItem) as MsOutlook.MailItem;
         if (mailItem != null)
         {
             mailItem.BodyFormat = MsOutlook.OlBodyFormat.olFormatHTML;
             mailItem.HTMLBody = GetMessage(fileName, link);
             mailItem.Display(false);
         }
     }
     catch (Exception e)
     {
         Logger.LogError(e);
     }
 }
예제 #2
0
파일: Reports.cs 프로젝트: CSSAdmin/TScan
        /// <summary>
        /// Opens the outlook with default default email client.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="reportPath">The report path.</param>
        /// <param name="reportDetails">The report details.</param>
        public static void OpenOutlook(string fileName, string reportPath, ReportDetails reportDetails)
        {
            string reportFilePath = Createpdf(fileName, reportPath, reportDetails);

            ////Commente by Biju on 27/Oct/2009 to implement outlook integration when Email button is clicked.

            ////StringBuilder mailstr = new StringBuilder();
            ////mailstr.Append("mailto:");
            ////mailstr.Append("&Attach=\"\"" + reportFilePath + "\"\"");
            ////Process emailProcess = new Process();
            ////emailProcess.StartInfo.FileName = mailstr.ToString();
            ////emailProcess.StartInfo.UseShellExecute = true;
            ////emailProcess.StartInfo.RedirectStandardOutput = false;
            ////emailProcess.Start();
            ////emailProcess.Dispose();

            ////Added by Biju on 27/Oct/2009 to implement outlook integration when Email button is clicked
            try
            {
                Outlook.ApplicationClass outlookApp = new Outlook.ApplicationClass();

                Outlook.MailItem outlookMail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                if (outlookMail == null)
                {
                    MessageBox.Show("Error occured while accessing Outlook. Please try again!", "TerraScan - Outlook Emailing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                outlookMail.Attachments.Add(reportFilePath, Outlook.OlAttachmentType.olEmbeddeditem, 1, "Terrascan");
                outlookApp.Inspectors.Add(outlookMail);
                if (outlookApp.Inspectors.Count > 0)
                {
                    outlookApp.Inspectors[outlookApp.Inspectors.Count].Activate();
                    outlookApp.Inspectors[outlookApp.Inspectors.Count].WindowState = Outlook.OlWindowState.olMaximized;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "TerraScan - Outlook Emailing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ////till here
        }
예제 #3
0
        public static void ReadOutlook()
        {
            Outlook._Application olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace   olNS  = olApp.GetNamespace("MAPI");
            olNS.Logon("@OutlookEmail", "@OutlookPassword", false, false);
            Outlook.MAPIFolder oFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            TodayDate = DateTime.Now.ToString("MM/dd/yyyy");
            Outlook.Items oItems = oFolder.Items.Restrict("[ReceivedTime] >= '" + TodayDate + "'");
            //Outlook.Items oItems = oFolder.Items.Restrict("[UnRead] = true");

            for (int i = 1; i <= oItems.Count; i++)
            {
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oItems[i];
                MailSubject = oMsg.Subject.ToString();
                MailBody    = System.Web.HttpUtility.JavaScriptStringEncode(oMsg.Body);

                if (MailSubject.StartsWith("RE:") || MailSubject.StartsWith("FW:") || MailSubject.StartsWith("Re:") || MailSubject.StartsWith("Fw:") || MailSubject.StartsWith("Fwd:"))
                {
                    // Do not fetch mail with contains word above (reply and forward type)
                }
                else
                {
                    EmailCount++;
                    NewEmailList.Add(MailSubject);
                    Console.WriteLine(MailSubject + MailBody);
                    CreatJiraIssue(MailSubject, MailBody);
                }
            }
            ListName = string.Join("\n", NewEmailList.ToArray());
            Console.WriteLine(EmailCount);
            Microsoft.Office.Interop.Outlook.MailItem oMsgSend = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMsgSend.To      = "######Recieved_Email######";
            oMsgSend.To      = "######Sender_Email######";
            oMsgSend.Subject = "Summary Auto Email Fetching " + TodayDate;
            oMsgSend.Body    = "All New Email count: " + EmailCount + "\n\nFetching complete: " + EmailCount + "\n\nList Email names: \n\n" + ListName;
            oMsgSend.Save();
            oMsgSend.Send();
        }
예제 #4
0
        //email list
        private void emailResult(string emailAddress, int countAttempted, int countFail)
        {
            Microsoft.Office.Interop.Outlook.ApplicationClass outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

            MailItem mailItem = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
            mailItem.To = emailAddress;

            mailItem.Subject = "Automated Message - QPR 2015 Summary";
            //mailItem.Body = "A total of " + countAttempted.ToString() + " QPRs were attempted, with " + countFail.ToString() + " failures";
            string msgBody = "A total of " + countAttempted.ToString() + " QPRs were attempted, with " + countFail.ToString() + " failures";
            string msg =
                   "<html>" +
                   "<body>" +
                   "<p style='font-size:12px; color: red; font-family:Arial, Helvetica, sans-serif;'> **** Automated Message ****</p>" +
                   "<p>"+ msgBody+ "</p> <br/>" +
                   "<p> Thank you!</p> <br/><br/>" +
                   " <img src='http://www.lahsa.org/images/LAHSAlogoCL.png' alt='LAHSA Logo'/></p>" +
                   "</body>" +
                   "</html>";
            mailItem.HTMLBody = msg;
            mailItem.Send();
        }
예제 #5
0
        //Email reports
        private void emailReports(string primaryEmail, string secondaryEmail, string cc1Email, string filePath)
        {
            Microsoft.Office.Interop.Outlook.ApplicationClass outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

            MailItem mailItem = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);

            Recipients oRecips = mailItem.Recipients;

            List<string> sToRecipList = new List<string>();
            List<string> sCCRecipList = new List<string>();

            //Add primary emails
            sToRecipList.Add(primaryEmail);
            sToRecipList.Add(secondaryEmail);

            //Add CC email
            sCCRecipList.Add(cc1Email);

            foreach (string t in sToRecipList)
            {
                Recipient oTORecip = oRecips.Add(t);
                oTORecip.Type = (int)OlMailRecipientType.olTo;
                oTORecip.Resolve();
            }

            foreach (string t in sCCRecipList)
            {
                Recipient oCCRecip = oRecips.Add(t);
                oCCRecip.Type = (int)OlMailRecipientType.olCC;
                oCCRecip.Resolve();
            }

            string msg =
                   "<html>" +
                   "<body>" +
                   "<p> Dear Providers</p><br/>" +
                   "<p>Your agency has been selected to receive this automated 2016 QPR Q1 (or Q4 for CNGF) before the deadline of October 7th, 2016.  This will give you a chance to review your data report and make any necessary corrections/changes/ or adjustments to this report.  Please note, if you have changed any data on or after September 6, 2016, your changes will not show on the attached QPR.  You will have to re-generate the report to see your changes.  All report data is live as of September 6, 2016.  The attached report is for your review so you can get a head start in making corrections for errors and validate all your client data before the October 7th deadline.</p> <br/>" +
                   "<p>Please contact [email protected] or your assigned LAHSA Data Analyst.  By providing these reports in advance, we are attempting to minimize QPR extension requests. Please start making data corrections in your APR and review all your data and Performance Targets. </p><br/>" +
                   "<p>If you have any questions or concerns, please feel free to email us.  Please kindly forward this message to the correct person if you are not responsible for reporting.</p><br/>" +
                   "<p> Sincerely,</p> <br/><br/>" +
                   "<p> LAHSAReports</p>" +
                   " <img src='http://www.lahsa.org/images/LAHSAlogoCL.png' alt='LAHSA Logo'/></p>"+
                   "</body>" +
                   "</html>";

            string subjectLine = "Automated QPR 2016 - Quarter 1";

            mailItem.SentOnBehalfOfName = "*****@*****.**";
            mailItem.HTMLBody = msg;
            mailItem.Subject = subjectLine;
            mailItem.Attachments.Add(filePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, filePath);

            mailItem.Send();
        }