public WHSMailService() { // get an instance of the MAPI namespace and login Outlook.Application app = new Outlook.ApplicationClass(); _nameSpace = app.GetNamespace("MAPI"); _nameSpace.Logon(null, null, false, false); }
public void TearDownSuite() { if(!m_bOutlookWasRunningBeforeTestStarted) m_outlookApplication.Quit(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(m_outlookApplication); m_outlookApplication = null; if (!m_bOutlookWasRunningBeforeTestStarted) { for (int iTry = 0; iTry < 5; ++iTry) { Thread.Sleep(500); if (!IsOutlookRuuning()) break; KillProcesses(); // must do better longer term } } PolicyLanguageCache.Instance().Reset(); RestoreMailProfile(); SetDisplayLogonProfileOption(m_orginalDisplayLogonProfile); }
private void ThisApplication_NewMail(string EntryIDCollection) { Outlook.ApplicationClass outLookApp = new Outlook.ApplicationClass(); NameSpace outLookNS = outLookApp.GetNamespace("MAPI"); MAPIFolder outLookFolder = outLookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox); string storeID = outLookFolder.StoreID; MailItem newEmail = (MailItem)outLookNS.GetItemFromID(EntryIDCollection, storeID); ThisApplication_OperateDataByEmail(newEmail); }
private MSOutlook.NameSpaceClass GetOutlookSession() { if (null == m_outlookSession) { MSOutlook.ApplicationClass app = new MSOutlook.ApplicationClass(); m_outlookSession = app.Session as MSOutlook.NameSpaceClass; m_outlookSession.Logon("Outlook", "", false, true); } return m_outlookSession; }
public void InitialiseSuite() { if (!MapiProfileHelperIsRegisterred()) { RegisterMapiProfileHelper(); { if (!MapiProfileHelperIsRegisterred()) throw new System.Exception("You need to register the MapiProfileHelper for these tests to run."); } } m_bOutlookWasRunningBeforeTestStarted = IsOutlookRuuning(); HideOutlookLogonProfileDialog(); SetMailProfile(); m_outlookApplication = new Microsoft.Office.Interop.Outlook.ApplicationClass(); LoadPolicy(); }
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); } }
/// <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 }
public EmailMessageHelper(string pstFile, string rootFolderName) { m_sender = new EmailSender(); m_app = m_sender.Initialise(); //Create a copy of the PST file and only work with the copy. m_pstCopy = String.Format("{0}{1}COPY.PST", Path.GetTempPath(), Path.GetFileNameWithoutExtension(pstFile)); File.Copy(pstFile, m_pstCopy, true); Assert.IsTrue( File.Exists( m_pstCopy )); m_mounter = new MailFolderMounter(m_app, m_pstCopy); MSOutlook.Folders folders = m_mounter.ETFolder.Folders; using (new ComObjectGovernor(folders)) { m_rootFolder = folders[rootFolderName]; Assert.IsNotNull(m_rootFolder, "Cannot find the folder containing the test emails"); } }
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(); }
public OutlookContactManager() { if (this.IsInstalled) { olSecurityManager = new AddinExpress.Outlook.SecurityManager(); try { _outlookApplication = new Microsoft.Office.Interop.Outlook.ApplicationClass(); } catch { errorCreatingOutlookApp = true; return; } try { olSecurityManager.ConnectTo(_outlookApplication); } catch { } } }
public static void ReadOutlookNightCrawler() { //I think ApplicationClass() works only if you have outlook installed Outlook.Application outlook = new Outlook.ApplicationClass(); Outlook.NameSpace ns = outlook.GetNamespace("Mapi"); object _missing = Type.Missing; ns.Logon(_missing, _missing, false, true); //Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Recipient recip = (Outlook.Recipient)ns.CreateRecipient("*****@*****.**"); Outlook.MAPIFolder inbox = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderInbox); int unread = inbox.UnReadItemCount; /* foreach (Outlook.MailItem mail in inbox.Items) { string s = mail.Subject; } */ Outlook.MailItem mitem = inbox.Items[1] as Outlook.MailItem; //mitem.PrintOut(); string AttachmentFolder = System.AppDomain.CurrentDomain.BaseDirectory + @"Attachments"; if (!Directory.Exists(AttachmentFolder)) { Directory.CreateDirectory(AttachmentFolder); } mitem.Attachments[1].SaveAsFile(System.AppDomain.CurrentDomain.BaseDirectory + "a"); }
//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(); }
//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(); }
private void HooksNewMail() { string pos = "ThisAddIn.HooksNewMail - "; log.Info(pos + "INIT"); Outlook.Application app = new Outlook.ApplicationClass(); _NameSpace ns = app.GetNamespace("MAPI"); ns.Logon(null, null, false, false); log.Info(pos + "Inizio hooking delle folder"); Outlook.Folders collectionFolders = ns.Folders; for (int i = 1; i <= collectionFolders.Count; i++) { if (collectionFolders[i].Store.DisplayName.ToLower().EndsWith(Constants.KP_DOMAIN.ToLower())) { log.Info(pos + "Hook della root:" + collectionFolders[i].Name); Outlook.Folder rootFolder = (Outlook.Folder)collectionFolders[i]; Outlook.Folders collectionRootFolders = rootFolder.Folders; for (int j = 1; j <= collectionRootFolders.Count; j++) { Outlook.Folder childFolder = (Outlook.Folder)collectionRootFolders[j]; log.Info(pos + "Hook della cartella:" + childFolder.Name); listItems.Add(childFolder.Items); listItems[j - 1].ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(FlagKpeopleMail); } } } log.Info(pos + "END"); }
private void buttonGetOutlookList_Click(object sender, EventArgs e) { bool _homeFax = false; bool _businessFax = false; string _homeFaxNumber = string.Empty; string _businessFaxNumber = string.Empty; Cursor.Current = Cursors.WaitCursor; try { Outlook.Application objOutlookTest = null; Outlook.NameSpace objNamespaceTest = null; Outlook.MAPIFolder objFolderTest = null; objOutlookTest = new Outlook.ApplicationClass(); objNamespaceTest = objOutlookTest.GetNamespace("MAPI"); objFolderTest = objNamespaceTest.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); int _count = objFolderTest.Items.Count; } catch (Exception er) { MessageBox.Show("Error getting Address book entries", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Common.Log(er.Message); Cursor.Current = Cursors.Default; return; } Outlook.Application objOutlook = null; Outlook.NameSpace objNamespace = null; Outlook.MAPIFolder objFolder = null; Outlook.ContactItem item = null; try { objOutlook = new Outlook.ApplicationClass(); objNamespace = objOutlook.GetNamespace("MAPI"); objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); Debug.WriteLine(objFolder.Items.Count + " Contacts found."); } catch (System.Exception ex) { Cursor.Current = Cursors.Default; Debug.WriteLine(ex.Message); } gridOutlookList.RowCount = 0; gridOutlookList.ColCount = 4; gridOutlookList.ColWidths[0] = 10; gridOutlookList.RowHeights[0] = 35; gridOutlookList.ColWidths[1] = 200; gridOutlookList.ColWidths[2] = 150; gridOutlookList.ColWidths[3] = 150; gridOutlookList.ColWidths[4] = 0; gridOutlookList[0, 1].Text = "Name"; gridOutlookList[0, 2].Text = "Business Fax"; gridOutlookList[0, 3].Text = "Home Fax"; gridOutlookList[0, 1].BackColor = Color.LightGray; gridOutlookList[0, 2].BackColor = Color.LightGray; gridOutlookList[0, 3].BackColor = Color.LightGray; gridOutlookList[0, 4].BackColor = Color.LightGray; objFolder.Items.Sort("LastNameAndFirstName", false); //gridOutlookList.RowCount = objFolder.Items.Count; for (int i = 1; i < objFolder.Items.Count + 1; i++) { try { _homeFax = false; _businessFax = false; //string _homeFaxNumber = string.Empty; //string _businessFaxNumber = string.Empty; try { item = (Outlook.ContactItem)objFolder.Items[i]; } catch { } try { //gridOutlookList[i, 4].Text = item.BusinessFaxNumber; _businessFaxNumber = item.BusinessFaxNumber; if (_businessFaxNumber.Length > 0) { _businessFax = true; } } catch { } try { //gridOutlookList[i, 5].Text = item.HomeFaxNumber; _homeFaxNumber = item.HomeFaxNumber; if (_homeFaxNumber.Length > 0) { _homeFax = true; } } catch { } if (_businessFax || _homeFax ) { gridOutlookList.RowCount = gridOutlookList.RowCount + 1; try { gridOutlookList[gridOutlookList.RowCount, 1].Text = item.LastNameAndFirstName; gridOutlookList[gridOutlookList.RowCount, 1].Enabled = false; } catch { } try { if (item.BusinessFaxNumber.Length > 0) { gridOutlookList[gridOutlookList.RowCount, 2].Description = item.BusinessFaxNumber; gridOutlookList[gridOutlookList.RowCount, 2].CellType = "PushButton"; gridOutlookList[gridOutlookList.RowCount, 2].CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised; } } catch { } try { if (item.HomeFaxNumber.Length > 0) { gridOutlookList[gridOutlookList.RowCount, 3].Description = item.HomeFaxNumber; gridOutlookList[gridOutlookList.RowCount, 3].CellType = "PushButton"; gridOutlookList[gridOutlookList.RowCount, 3].CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised; } } catch { } } } catch { } } SortCol(1, gridOutlookList); gridOutlookList[0, 1].CellAppearance = GridCellAppearance.Raised; Cursor.Current = Cursors.Default; }