private void Feedback() { try { if (check()) { Microsoft.Office.Interop.Outlook.Application opp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)opp.CreateItem(0); mail.To = "*****@*****.**"; mail.Subject = this.cboSub.Text + ": " + txtSub.Text; mail.Body = this.txtBody.Text + System.Environment.NewLine + System.Environment.NewLine + "Sent using " + lblVer.Text; mail.Send(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "One Click Functions", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
public void convert() { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); // Iterate files in prod issues string[] mailFiles = Directory.GetFiles(MAILPATH); foreach (string file in mailFiles) { Console.WriteLine("Processing file: " + file); // Open msg file var item = app.Session.OpenSharedItem(file) as Microsoft.Office.Interop.Outlook.MailItem; // Read body string body = item.Body; // Create filename to write string txtFilePath = TEXTPATH + Path.GetFileNameWithoutExtension(file); // Create new text file + Write body to new text file File.AppendAllText(txtFilePath, body); Console.WriteLine("Outputting to: " + txtFilePath); } Console.ReadLine(); }
public MailTable IndexSinglePst() { Microsoft.Office.Interop.Outlook.Application otlApplication = new Microsoft.Office.Interop.Outlook.Application(); try { Outlook.NameSpace otlNameSpace = otlApplication.GetNamespace("MAPI"); Outlook.Store otlStore = otlNameSpace.PickFolder().Store; System.IO.FileInfo fi = new System.IO.FileInfo(otlStore.FilePath); this.mailTable = new MailTable((new System.IO.FileInfo(otlStore.FilePath)).Name); this.mailTable.ModifiedData = fi.FullName + fi.Length.ToString(); //this.mailTable.BaseTable = GMS.MailTable.getTable(this.mailTable.BaseTable, basetable.Select("StoreID<>'"+otlStore.StoreID.ToString()+"'")); try { analyseFolder((Outlook.Folder)otlStore.GetRootFolder()); } catch { } } catch { } finally { otlApplication = null; } return(this.mailTable); }
protected override List <UploadItem> SetUploadItemFilePath(string sourceFolder, string filePath, UploadItem uploadItem) { if (ConfigurationManager.GetInstance().Configuration.OutlookConfigurations.SaveAsWord&& Path.GetExtension(filePath) == ".msg") { List <UploadItem> additionalItems = new List <UploadItem>(); Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlook.CreateItemFromTemplate(filePath); string newFileName = filePath.Substring(0, filePath.LastIndexOf('.')) + ".doc"; mailItem.SaveAs(newFileName, Microsoft.Office.Interop.Outlook.OlSaveAsType.olDoc); foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mailItem.Attachments) { string extensionName = String.Empty; string filenameWithoutExtension = String.Empty; string fileName = String.Empty; GetFileNameAndExtension(attachment.FileName, out filenameWithoutExtension, out extensionName); filePath = GetUnuqieFileName(sourceFolder, filenameWithoutExtension, extensionName, out fileName);//keep original name attachment.SaveAsFile(filePath); UploadItem attachmentItem = new UploadItem(); attachmentItem.Folder = uploadItem.Folder; attachmentItem.ContentType = uploadItem.ContentType; attachmentItem.FieldInformations = uploadItem.FieldInformations; attachmentItem.FilePath = filePath; additionalItems.Add(attachmentItem); } uploadItem.FilePath = newFileName; return(additionalItems); } else { base.SetUploadItemFilePath(sourceFolder, filePath, uploadItem); return(null); } }
override public void DeleteAppointment(SubCalendarEvent ActiveSection, string NameOfParentCalendarEvent = "", string entryID = "") { #if EnableOutlook if (entryID == "") { return; } Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); Outlook.MAPIFolder calendar = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); Outlook.Items calendarItems = calendar.Items; try { string SubJectString = ActiveSection.getId + "**" + NameOfParentCalendarEvent; if (ActiveSection.getIsComplete) { //SubJectString = ActiveSection.ID + "*\u221A*" + NameOfParentCalendarEvent; } Outlook.AppointmentItem item = calendarItems[SubJectString] as Outlook.AppointmentItem; item.Delete(); } catch (Exception e) { return; } #endif }
private void btnSend_Click(object sender, EventArgs e) { try { if (check()) { Microsoft.Office.Interop.Outlook.Application opp = new Microsoft.Office.Interop.Outlook.Application(); if (opp.DefaultProfileName != null) { Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)opp.CreateItem(0); mail.To = "*****@*****.**"; mail.Subject = this.cboSub.Text + " for Kinect Slider: " + txtSub.Text; mail.Body = this.txtBody.Text + System.Environment.NewLine + System.Environment.NewLine + "Kinect Slider" + System.Environment.NewLine + "Sent using " + lblVer.Text; mail.Send(); this.Close(); MessageBox.Show("Thank you for your feedback!", "Kinect Slider", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Couldnt find a Outlook profile. Please send a mail to [email protected]", "Kinect Slider", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "PowerPoint Kinect Slider", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
public override List <ApplicationItemProperty> GetApplicationFields(string filePath) { List <ApplicationItemProperty> returnApplicationItemProperties = new List <ApplicationItemProperty>(); List <ApplicationItemProperty> applicationItemProperties = ConfigurationManager.GetInstance().GetApplicationItemProperties(ApplicationTypes.Outlook); Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = null; if (filePath == null) { mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); } else { mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlook.CreateItemFromTemplate(filePath); } Microsoft.Office.Interop.Outlook.ItemProperties properties = mailItem.ItemProperties; for (int i = 0; i < properties.Count; i++) { Microsoft.Office.Interop.Outlook.ItemProperty property = properties[i]; ApplicationItemProperty applicationItemProperty = applicationItemProperties.FirstOrDefault(item => item.Name == property.Name); if (applicationItemProperty != null) { ApplicationItemProperty returnApplicationItemProperty = new ApplicationItemProperty( applicationItemProperty.Name, applicationItemProperty.DisplayName, applicationItemProperty.Type); returnApplicationItemProperty.Value = Convert.ChangeType(property.Value, applicationItemProperty.Type); returnApplicationItemProperties.Add(returnApplicationItemProperty); } } #region Writing the xml for field definitions /* * System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter("c:\\fields.xml", Encoding.UTF8); * // start writing! * writer.WriteStartDocument(); * writer.WriteStartElement("Outlook"); * writer.WriteStartElement("MailItem"); * writer.WriteStartElement("ItemProperties"); * System.Xml.XmlDocument document = new System.Xml.XmlDocument(); * System.Xml.XmlNode mainNode = document.CreateNode(System.Xml.XmlNodeType.Element, "MailItem", "Outlook"); * for (int i = 0; i < properties.Count; i++) * { * writer.WriteStartElement("Property"); * writer.WriteAttributeString("Name", properties[i].Name); * writer.WriteAttributeString("DisplayName", properties[i].Name); * writer.WriteAttributeString("Type", properties[i].Type.ToString()); * writer.WriteEndElement(); * } * writer.WriteEndElement(); * writer.WriteEndElement(); * writer.WriteEndElement(); * writer.WriteEndDocument(); * writer.Close(); */ #endregion return(returnApplicationItemProperties); }
public bool BuildCatalogue(string outfolder) { bool unchanged = true; Microsoft.Office.Interop.Outlook.Application otlApplication = new Microsoft.Office.Interop.Outlook.Application(); try { Outlook.NameSpace otlNameSpace = otlApplication.GetNamespace("MAPI"); foreach (Outlook.Store otlStore in otlNameSpace.Stores) { if (otlStore.DisplayName == "Public Folders") { continue; } string pststamp = StampPST((Outlook.Folder)otlStore.GetRootFolder()); System.IO.FileInfo fi = new System.IO.FileInfo(otlStore.FilePath); this.mailTable = new MailTable(fi.Name); System.IO.FileInfo mtfi = new System.IO.FileInfo(outfolder + "\\" + this.mailTable.FileName); if (mtfi.Exists) { try { MailTable mt = new Serializer().DeSerializeObject(mtfi.FullName); if (pststamp == mt.ModifiedData) { continue; } } catch { } } unchanged = false; try { analyseFolder((Outlook.Folder)otlStore.GetRootFolder()); } catch { } this.mailTable.ModifiedData = pststamp; new Serializer().SerializeObject(outfolder, this.mailTable); } } catch { } finally { otlApplication = null; } return(unchanged); }
public override void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams) { List <string> _fileNames = new List <string>(); List <MemoryStream> _filestreams = new List <MemoryStream>(); string sourceFolder = ConfigurationManager.GetInstance().CreateATempFolder(); Microsoft.Office.Interop.Outlook.Application application = Application as Microsoft.Office.Interop.Outlook.Application; for (int i = 1; i <= application.ActiveExplorer().Selection.Count; i++) { Object temp = application.ActiveExplorer().Selection[i]; if (temp is Microsoft.Office.Interop.Outlook.MailItem) { Microsoft.Office.Interop.Outlook.MailItem mailitem = (temp as Microsoft.Office.Interop.Outlook.MailItem); string fileName = mailitem.Subject + ".msg"; string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { fileName = fileName.Replace(c.ToString(), ""); } string filePath = sourceFolder + "\\" + fileName; mailitem.SaveAs(filePath); MemoryStream ms = new MemoryStream(); using (FileStream fs = File.OpenRead(filePath)) { fs.CopyTo(ms); } _fileNames.Add(fileName); _filestreams.Add(ms); } } filenames = _fileNames.ToArray(); filestreams = _filestreams.ToArray(); /* * //wrap standard IDataObject in OutlookDataObject * OutlookDataObject dataObject = new OutlookDataObject(data); * * try * { * //get the names and data streams of the files dropped * filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); * filestreams = (MemoryStream[])dataObject.GetData("FileContents"); * } * catch (Exception ex) * { * string subject = ((string)dataObject.GetData("Text")).Split(new char[]{'\n'})[1].Split(new char[]{'\t'})[1]; * filenames = new string[]{subject}; * filestreams = new MemoryStream[] { (MemoryStream)dataObject.GetData("Object Descriptor") }; * } */ }
private static List <Outlook.Folder> _EnumerateCalendards() { var oApp = new Microsoft.Office.Interop.Outlook.Application(); Outlook.Folder root = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; var folders = new List <Outlook.Folder>() { root }; EnumerateFolders(root, folders); return(folders); }
private void CreateMailItem(String Subject) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mailItem.Subject = Subject + " " + currentDate.ToString("dd MMMM yyyy") + " - " + currentDate.ToString("hh:mm:ss tt"); mailItem.To = strTOMAIL; mailItem.Body = "Hi\n\nPlease find my today's " + Subject + " " + currentDate.ToString("dd MMMM yyyy") + " - " + currentDate.ToString("hh:mm:ss tt") + "." + "\n\nSystem Details:\nUser Name: " + user_name + "\nHOSTNAME: " + hostname + "\nIP Address:" + IP_Address + "\nMAC Address: " + MAC_Address + "\nDOMAIN: " + domain_name + "\n\nThis is autogenerated email sent by Time Management System.\n\nThanks & Regards\n" + user_name; //mailItem.Attachments.Add(attachment_path); //attachment_path is a string holding path of the attachment mailItem.Importance = Outlook.OlImportance.olImportanceHigh; mailItem.Display(false); mailItem.Send(); }
override public string AddAppointment(SubCalendarEvent ActiveSection, string NameOfParentCalendarEvent = "") { if (!ActiveSection.isEnabled) { return(""); } #if EnableOutlook try { Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)app.CreateItem(Outlook.OlItemType.olAppointmentItem); /*(Outlook.AppointmentItem) * this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);*/ newAppointment.Start = ActiveSection.Start.toTimeZoneTime().DateTime; // DateTimeOffset.Now.AddHours(2); newAppointment.End = ActiveSection.End.toTimeZoneTime().DateTime; // DateTimeOffset.Now.AddHours(3); newAppointment.Location = "TBD"; newAppointment.Body = "JustTesting"; newAppointment.AllDayEvent = false; string SubJectString = ActiveSection.getId + "**" + NameOfParentCalendarEvent; if (ActiveSection.getIsComplete) { //SubJectString = ActiveSection.ID + "*\u221A*" + NameOfParentCalendarEvent; } newAppointment.Subject = SubJectString;// ActiveSection.ID + "**" + NameOfParentCalendarEvent; /*newAppointment.Recipients.Add("Roger Harui"); * Outlook.Recipients sentTo = newAppointment.Recipients; * Outlook.Recipient sentInvite = null; * sentInvite = sentTo.Add("Holly Holt"); * sentInvite.Type = (int)Outlook.OlMeetingRecipientType * .olRequired; * sentInvite = sentTo.Add("David Junca "); * sentInvite.Type = (int)Outlook.OlMeetingRecipientType * .olOptional; * sentTo.ResolveAll();*/ newAppointment.Save(); //newAppointment.EntryID; //newAppointment.Display(true); return(newAppointment.EntryID); } catch (Exception ex) { //MessageBox.Show("The following error occurred: " + ex.Message); return(""); } #endif return(""); }
static void MailOperations() { Console.WriteLine("Do You want to Compose a Mail with the Same Excel Attachement? Press [Y] for Yes any other key for N"); string input = Console.ReadLine(); if (input.ToLower().Contains("y")) { try { // Create the Outlook application. Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email var statusDate = StatusDate.ToString("dd MMMM"); oMsg.Subject = "WP Daily Update – Subha Deb - " + statusDate; StringBuilder htmlBody = new StringBuilder(); htmlBody.Append("Hi,<br/> <br/> PFA the Status for " + statusDate); htmlBody.Append("<br/> <br/> Thanks, <br> Subha Deb"); oMsg.HTMLBody = htmlBody.ToString(); //Add an attachment. int iPosition = (int)oMsg.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; //now attached the file Outlook.Attachment oAttach = oMsg.Attachments.Add(GeneratedExcelFileNamePath, iAttachType, iPosition); // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. foreach (var email in ReceipentsEmailIdsList) { Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email); oRecip.Resolve(); oRecip = null; } oMsg.Display(true); // Send. //oMsg.Send(); // Clean up. oRecips = null; oMsg = null; oApp = null; }//end of try block catch (Exception ex) { Console.WriteLine("Got Exception"); Console.WriteLine(ex.ToString()); }//end of catch } }
/// <summary> /// prints out all the folder names (used for testing) /// </summary> private void printFolders() { var appOutlook = new Microsoft.Office.Interop.Outlook.Application(); var folders = appOutlook.Session.Folders; var stores = appOutlook.Session.Stores; Console.WriteLine(stores.GetType()); foreach (Microsoft.Office.Interop.Outlook.Store store in stores) { Console.WriteLine(store.DisplayName); } }
public void SendEmail(string strTo, string strCC, string strSubject, string strHtmlBody) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Outlook.MailItem item = app.CreateItem(Outlook.OlItemType.olMailItem); item.HTMLBody = strHtmlBody; item.To = strTo; item.CC = strCC; item.Subject = strSubject; item.Recipients.ResolveAll(); item.Send(); }
public static void openEmail(string emailid, string storeid) { Microsoft.Office.Interop.Outlook.Application otlApplication = new Microsoft.Office.Interop.Outlook.Application(); try { Outlook.NameSpace otlNameSpace = otlApplication.GetNamespace("MAPI"); Outlook.MailItem mi = (Outlook.MailItem)otlNameSpace.GetItemFromID(emailid, storeid); mi.Display(false); } catch (Exception exp) { throw new Exception("PST not there" + exp.Message); } finally { otlApplication = null; } }
/// <summary> /// Retrieves all the stores tied to the outlook account currently opened /// </summary> /// <returns> a List containing all the inboxes in an outlook account</returns> public List <Outlook.Store> getStores() { List <Outlook.Store> stores = new List <Outlook.Store>(); var appOutlook = new Microsoft.Office.Interop.Outlook.Application(); // Get each store in the outlook account var outlookStores = appOutlook.Session.Stores; // add each store to a list (can most likely forgoe this and just return outlookStores foreach (Outlook.Store store in outlookStores) { stores.Add(store); } return(stores); }
public void ComposeEmail(string strTo, string strCC, string strSubject, string strHtmlBody, string strFolderEntryID, string strFolderStoreID) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Outlook.Folder DestFolder = app.Session.GetFolderFromID(strFolderEntryID, strFolderStoreID) as Outlook.Folder; Outlook.MailItem item = app.CreateItem(Outlook.OlItemType.olMailItem); item.HTMLBody = strHtmlBody; item.To = strTo; item.CC = strCC; item.Subject = strSubject; item.Display(); item.Save(); item.Move(DestFolder); }
private String sendEmail(String subject, String body, String[] receivers) { try { //if Outlook is not open start it and wait Process[] pName = Process.GetProcessesByName("OUTLOOK"); if (pName.Length == 0) { // Open Outlook anew. System.Diagnostics.Process.Start("OUTLOOK.EXE"); System.Threading.Thread.Sleep(2000); } //**** Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); //The email receiver //recipients Microsoft.Office.Interop.Outlook.Recipients recipients = mailItem.Recipients as Microsoft.Office.Interop.Outlook.Recipients; foreach (var email in receivers) { recipients.Add(email); } mailItem.Subject = subject; mailItem.Body = body; mailItem.Send(); return("sent"); } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == -2147417846) { return("This Programm Use Outlock Service To Send Your Email, You Need To Execute Outlock First Than Send Your Email."); } else { //return "Error, Email was Not sent"; return("sent"); } } }
private void LoadContactsList() { Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); Outlook.Folder contactsFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Outlook.Folder; Outlook.Folder currentFolder = outlookApp.ActiveExplorer().CurrentFolder as Outlook.Folder; Outlook.Store currentStore = currentFolder.Store; Outlook.AddressList addressList = this.GetGlobalAddressList(outlookApp, currentStore); Outlook.AddressEntries entries = addressList.AddressEntries; this._contactsList = new List <Contact>(); foreach (Outlook.AddressEntry entry in entries) { Outlook.ExchangeDistributionList distList = entry.GetExchangeDistributionList(); Outlook.ExchangeUser user = entry.GetExchangeUser(); Outlook.ContactItem contact = entry.GetContact(); if (distList != null) { this._contactsList.Add(new Contact(distList.Name, distList.PrimarySmtpAddress)); } if (contact != null) { this._contactsList.Add(new Contact(contact.FirstName + " " + contact.LastName, contact.IMAddress)); } if (user != null) { if (user.FirstName == null && user.LastName == null) { this._contactsList.Add(new Contact(user.Name, user.PrimarySmtpAddress)); } else { this._contactsList.Add(new Contact(user.FirstName + " " + user.LastName, user.PrimarySmtpAddress)); } } } }
public void send_email_via_outlook(bool battach, string filepath) { try { Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application(); Outlook.MailItem mailItem = (Outlook.MailItem)outlookObj.CreateItem(Outlook.OlItemType.olMailItem); mailItem.Subject = "windows undocumented api demo"; mailItem.To = "*****@*****.**"; mailItem.Body = "hogehoge"; if (battach == true) { mailItem.Attachments.Add(filepath); //logPath is a string holding path to the log.txt file } mailItem.Display(false); } catch (Exception ex) { } }
//public string DailyMediaReportSMTP(DateTime todaysdate) //{ // try // { // string fileName = Server.MapPath("../") + "Report\\" + "DailyMediaReport -11-20-2018.pdf"; // //fileName = "\\dpw-cisweb-tst\\E$\\Inetpub\\WWWRoot\\Communications\\" + "Report\\" + fileName; // OpenOutLookSMTP(fileName);//DailyMediaReport -11-20-2018 // return "true"; // } // catch (Exception ex) // { // var resultPdfReport = new { Valid = false, Message = ex.InnerException }; // var exeception = ex.Message; // // andy // //return false; // return exeception; // } // finally // { // //check stream length or if stream not close, close stream // //Same here, use report.Close(); // } //} //Old method-HP public void OpenOutLook(string fileName) { Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); //Verify it haritha //Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem) //using oMsg{ //oMsg.To = "Daily Media Report Contacts"; oMsg.To = "*****@*****.**"; oMsg.Subject = "Department of Public Works Daily Media Log for " + System.DateTime.Now.ToShortDateString() + "."; oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; oMsg.HTMLBody = "The attached log sheet reflects media contact information as of 2:30 p.m. today. Information received" + " afterwards will be listed on next day\'s log with date noted."; //oMsg.HTMLBody = // "The attached log sheet reflects media contact information as of " + System.DateTime.Now.ToShortTimeString() + " today. Information received" + // " afterwards will be listed on next day\'s log with date noted."; oMsg.Attachments.Add(fileName, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing); oMsg.Display(oMsg); // } }
public void SendEmail() { //MessageBox.Show("In Send Email"); Microsoft.Office.Interop.Outlook.Application app = null; Microsoft.Office.Interop.Outlook.MailItem mailItem = null; try { //var emailTo = "*****@*****.**"; //mailItem.To = emailTo; app = new Outlook.Application(); mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mailItem.To = ToBox.Text.ToString(); mailItem.Subject = SubjectBox.Text.ToString(); mailItem.Body = BodyBox.Text.ToString(); List <string> CC = CCBox.Text.Split(',').ToList(); Outlook.Recipients recips = (Outlook.Recipients)mailItem.Recipients; foreach (string email in CC) { Outlook.Recipient recip = (Outlook.Recipient)recips.Add(email); recip.Type = (int)Outlook.OlMailRecipientType.olCC; } string log = "Email sent to " + mailItem.To.ToString(); ((Outlook._MailItem)mailItem).Send(); MessageBox.Show(log); } finally { if (app != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app); } if (mailItem != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(mailItem); } this.Close(); } }
public MOM_Form(String calendarEntryId, Microsoft.Office.Interop.Outlook.MAPIFolder calendar, Microsoft.Office.Interop.Outlook._NameSpace ns, String inviteeList, Dictionary <String, String> mapDict, Microsoft.Office.Interop.Outlook.Application appl) { InitializeComponent(); panel1.Height = 30; panel_next_meeting_atch1.Height = 25; btnMenuGroup1.Image = MOMOutlookAddIn.Properties.Resources.down; //This method will initialize the button toolbar for the text editor PredefinedButtonSets.SetupDefaultButtons(this.meetingNotes); //PredefinedButtonSets.SetupDefaultButtons(this.nextMeetingBody); //meetingNotes.ShowSelectionMargin = true; if (mapDict != null) { emailNameMappingDict = mapDict; } else { emailNameMappingDict = new Dictionary <string, string>(); } app = appl; populateTimeCombo(); button_Add_Action.Enabled = false; Outlook.AppointmentItem calItem = (Outlook.AppointmentItem)ns.GetItemFromID(calendarEntryId, calendar.StoreID); if (calItem != null) { meetingname.Text = calItem.Subject.Trim(); meetingDate.Text = calItem.Start.ToString().Substring(0, calItem.Start.ToString().IndexOf(" ")); starttime.Text = calItem.Start.ToString().Substring(calItem.Start.ToString().IndexOf(" ") + 1); endtime.Text = calItem.End.ToString().Substring(calItem.End.ToString().IndexOf(" ") + 1); location.Text = calItem.Location != null?calItem.Location.Trim() : ""; minutestaken.Text = System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName; chair.Text = calItem.Organizer.Trim(); inviteeListString = inviteeList; nextMeetingItem = findNextOccuranceOfThisMeeting(meetingname.Text, calendar, calItem, inviteeList); populateAssignedToListBoxAndAttendeeCheckBox(); } //minutestaken.Text=calItem.c }
public AddRecipient() { InitializeComponent(); Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace outlookNameSpace = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = outlookNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder contactsFolder = outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook. OlDefaultFolders.olFolderContacts); contactItems = contactsFolder.Items; // listBox_Contacts.Items.Add(app.Session.CurrentUser.Name); foreach (object item in contactItems) { listBox_Contacts.Items.Add(((ContactItem)item).FullName); } }
public static List <WorktimeRecord> retrieveAppointments(DateTime from, DateTime to) { var oApp = new Microsoft.Office.Interop.Outlook.Application(); Outlook.Folder calFolder = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, from, to); var ret = new List <WorktimeRecord>(); if (rangeAppts != null) { foreach (Outlook.AppointmentItem appt in rangeAppts) { //MessageBox.Show("Subject: " + appt.Subject + " Start: " + appt.Start.ToString("g")); //Ignore 0 length appointments if ((appt.End - appt.Start).TotalMinutes < 1) { continue; } //Ignore all day events that are not "alone", assuming these events are more like placeholders if (appt.AllDayEvent && appt.Conflicts?.GetFirst() != null) { continue; } //Assume that appointments marked as free or OOO are more like "reminders" if (appt.BusyStatus == Outlook.OlBusyStatus.olFree || appt.BusyStatus == Outlook.OlBusyStatus.olOutOfOffice) { continue; } ret.Add(new WorktimeRecord(appt.Start, appt.End, "[unknown-outl]", appt.Subject)); } } return(ret); }
//отправляем каждому необходимые работы void SendEmails() { string prform_path; for (int i = 0; i < peers.Count; i++) { for (int j = 0; j < peers[i].new_guids.Count; j++) { prform_path = session.Folder_path + @"\Review " + peers[i].guids_ID[j] + ".xlsm"; File.Copy(@"..\..\..\PATemplate_Example.xlsm", prform_path); Excel.Application xlApp = new Excel.Application(); Excel.Workbook Book = xlApp.Workbooks.Open(prform_path); Excel.Worksheet Sheet = Book.Sheets[1]; Sheet.Cells[1, 2] = peers[i].prform_IDs[j]; Book.Close(true); xlApp.Quit(); Book = null; Sheet = null; Microsoft.Office.Interop.Outlook._Application _app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)_app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mail.To = peers[i].email; mail.Subject = peers[i].prform_IDs[j] + " review for " + session.TaskTitle + peers[i].new_guids[j]; mail.Body = "Hello!" + "\n" + "\t" + "Please see attached files." + "\n" + "Reply to this message with attached complete PR form (" + peers[i].prform_IDs[j] + ".xlsm) only." + "\n" + "Deadline for reviews is " + session.Review_End + "." + "\n\t" + "Truly yours, Peer Review Robot."; mail.Attachments.Add(prform_path); mail.Attachments.Add(Directory.GetFiles(session.Folder_path, $"{peers[i].new_guids[j]}*")[0]); mail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal; Outlook.Account account = GetOutlookAccount(_app, session.OutlookAccount); mail.SendUsingAccount = account; mail.Send(); _app.Quit(); _app = null; mail = null; File.Delete(prform_path); } } }
private void button1_Click_1(object sender, EventArgs e) { try { DataSet ds = new DataSet(); ds.Tables.Add("Contacts"); ds.Tables[0].Columns.Add("Email"); ds.Tables[0].Columns.Add("FirstName"); ds.Tables[0].Columns.Add("LastName"); Microsoft.Office.Interop.Outlook.Items OutlookItems; Microsoft.Office.Interop.Outlook.Application outlookObj; Microsoft.Office.Interop.Outlook.MAPIFolder Folder_Contacts; outlookObj = new Microsoft.Office.Interop.Outlook.Application(); Folder_Contacts = (Microsoft.Office.Interop.Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts); OutlookItems = Folder_Contacts.Items; for (int i = 0; i < OutlookItems.Count; i++) { Microsoft.Office.Interop.Outlook.ContactItem contact = (Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i + 1]; DataRow dr = ds.Tables[0].NewRow(); txtUserData.Text += contact.Email1Address; txtUserData.Text += contact.FirstName; txtUserData.Text += contact.LastName; dr[0] = contact.Email1Address; dr[1] = contact.FirstName; dr[2] = contact.LastName; ds.Tables[0].Rows.Add(dr); } } catch (Exception ex) { } }
private void Frnd() { try { if (check()) { Microsoft.Office.Interop.Outlook.Application opp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)opp.CreateItem(0); mail.To = txtTO.Text; mail.Subject = txtSub.Text; mail.Body = txtBody.Text; mail.Send(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "One Click Functions", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
public void DeleteAppointment(SubCalendarEvent ActiveSection, string NameOfParentCalendarEvent, string entryID) { #if EnableOutlook if (entryID == "") { return; } Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); Outlook.MAPIFolder calendar = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); Outlook.Items calendarItems = calendar.Items; try { string SubJectString = ActiveSection.ID + "**" + NameOfParentCalendarEvent; if (ActiveSection.isComplete) { //SubJectString = ActiveSection.ID + "*\u221A*" + NameOfParentCalendarEvent; } Outlook.AppointmentItem item = calendarItems[SubJectString] as Outlook.AppointmentItem; item.Delete(); } catch { return; } /*Outlook.RecurrencePattern pattern = item.GetRecurrencePattern(); Outlook.AppointmentItem itemDelete = pattern. GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0)); if (itemDelete != null) { itemDelete.Delete(); }*/ #endif }
/// <summary> /// 预约会议响应事件 /// </summary> /// <param name="Ctrl"></param> /// <param name="CancelDefault"></param> public static void btnSchedule_Click(CommandBarButton Ctrl, ref bool CancelDefault) { ThisAddIn.g_log.Info("operator:btnCreateTPConfClicked begin"); try { //创建会议 Microsoft.Office.Interop.Outlook.Application ap = new Microsoft.Office.Interop.Outlook.Application(); Outlook.AppointmentItem appt = ap.CreateItem(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem; if (null != appt) { appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; appt.BusyStatus = Outlook.OlBusyStatus.olBusy; CreateUserProperties(ref appt);//创建自定义属性 Outlook.UserProperty property = appt.UserProperties.Find(ThisAddIn.PROPERTY_ENTER_FROM_SELF, Type.Missing); if (property != null) { property.Value = true; } appt.Display(false); } } catch (System.Exception ex) { ThisAddIn.g_log.Error(string.Format("create appointmentItem error: {0}", ex.ToString())); return; } //进入预约会议之前,弹出选择智真会议室提示框 if (ThisAddIn.g_SystemSettings.bShowTipsForSelectRooms == true) { TipsForSelectRoomsForm tips = new TipsForSelectRoomsForm(); tips.StartPosition = FormStartPosition.CenterScreen; tips.ShowDialog(); } ThisAddIn.g_log.Info("operator:btnCreateTPConfClicked end"); }
public static string SaveTopEmail(string strMailbox, string strFolder1, string strFolder2, string strFolder3, string strFileTarget) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); int intFolderCount = 0; int intItemsCount = 0; string strFolderFound = "N"; Outlook.MAPIFolder fldrsource = app.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent; string strEntryID = ""; string strStoreId = ""; string strLevel = ""; if (strMailbox.ToString().Trim() != "") { strLevel = "1"; foreach (Outlook.MAPIFolder fldrmlbox in app.GetNamespace("MAPI").Folders) { if (fldrmlbox.Name.ToString().ToLower().Trim() == strMailbox.ToString().ToLower().Trim()) { strLevel = "2"; if (strFolder1.ToString().Trim() != "") { intFolderCount = fldrmlbox.Folders.Count; if (intFolderCount > 0) { strLevel = "3"; foreach (Outlook.MAPIFolder fldrlvl1 in fldrmlbox.Folders) { if (fldrlvl1.Name.ToString().ToLower().Trim() == strFolder1.ToString().ToLower().Trim()) { strLevel = "4"; if (strFolder2.ToString().Trim() != "") { strLevel = "5"; intFolderCount = fldrlvl1.Folders.Count; if (intFolderCount > 0) { strLevel = "6"; foreach (Outlook.MAPIFolder fldrlvl2 in fldrlvl1.Folders) { strLevel = "7" + fldrlvl2.Name.ToString().ToLower().Trim(); if (fldrlvl2.Name.ToString().ToLower().Trim() == strFolder2.ToString().ToLower().Trim()) { strLevel = "8"; if (strFolder3.ToString().Trim() != "") { intFolderCount = fldrlvl2.Folders.Count; if (intFolderCount > 0) { foreach (Outlook.MAPIFolder fldrlvl3 in fldrlvl1.Folders) { if (fldrlvl3.Name.ToString().ToLower().Trim() == strFolder3.ToString().ToLower().Trim()) { fldrsource = fldrlvl3; strFolderFound = "Y"; break; } } } } else { fldrsource = fldrlvl2; strFolderFound = "Y"; } break; } } } } else { fldrsource = fldrlvl1; strFolderFound = "Y"; } break; } } } } else { fldrsource = fldrmlbox; strFolderFound = "Y"; } break; } } } strLevel = "9"; if (strFolderFound == "Y") { intItemsCount = fldrsource.Items.Count; if (intItemsCount > 0) { foreach (Outlook.MailItem themailitem in fldrsource.Items) { if ((themailitem as Outlook.MailItem) != null) { themailitem.SaveAs(strFileTarget, Outlook.OlSaveAsType.olMSG); strEntryID = themailitem.EntryID; strStoreId = themailitem.Parent.StoreID; break; } } } } return("" + strFolderFound + "|xxx|" + strEntryID + "|xxx|" + strStoreId + ""); }
private string AddAppointment(SubCalendarEvent ActiveSection, string NameOfParentCalendarEvent) { try { Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)app.CreateItem(Outlook.OlItemType.olAppointmentItem); /*(Outlook.AppointmentItem) this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);*/ newAppointment.Start = ActiveSection.Start;// DateTime.Now.AddHours(2); newAppointment.End = ActiveSection.End;// DateTime.Now.AddHours(3); newAppointment.Location = "TBD"; newAppointment.Body ="JustTesting"; newAppointment.AllDayEvent = false; newAppointment.Subject = ActiveSection.ID + "**" + NameOfParentCalendarEvent; /*newAppointment.Recipients.Add("Roger Harui"); Outlook.Recipients sentTo = newAppointment.Recipients; Outlook.Recipient sentInvite = null; sentInvite = sentTo.Add("Holly Holt"); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olRequired; sentInvite = sentTo.Add("David Junca "); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olOptional; sentTo.ResolveAll();*/ newAppointment.Save(); //newAppointment.EntryID; //newAppointment.Display(true); return newAppointment.EntryID; } catch (Exception ex) { MessageBox.Show("The following error occurred: " + ex.Message); return ""; } }
public void Flag(Element element, bool hasStart, DateTime startDate, CustomTimeSpan startTime, bool isStartAllDay, bool hasDue, DateTime dueDate, CustomTimeSpan dueTime, bool isDueAllDay, bool addToToday, bool addToReminder, bool addToTask) { Outlook.Application outlook_app = new Microsoft.Office.Interop.Outlook.Application(); Outlook.AppointmentItem app_item; Outlook.TaskItem task_item; if (hasStart || hasDue) { app_item = outlook_app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem) as Microsoft.Office.Interop.Outlook.AppointmentItem; if (isStartAllDay) { app_item.Start = startDate; app_item.AllDayEvent = true; element.StartDate = startDate; element.DueDate = startDate.AddDays(1); } else { if (startTime.IsAM == false) { startTime.Hour += 12; } string startDateTime = startDate.Month.ToString() + "/" + startDate.Day.ToString() + "/" + startDate.Year.ToString() + " " + startTime.Hour.ToString() + ":" + startTime.Minutes.ToString() + ":00"; if (dueTime.IsAM == false) { dueTime.Hour += 12; } string dueDateTime = dueDate.Month.ToString() + "/" + dueDate.Day.ToString() + "/" + dueDate.Year.ToString() + " " + dueTime.Hour.ToString() + ":" + dueTime.Minutes.ToString() + ":00"; app_item.Start = System.DateTime.Parse(startDateTime); app_item.End = System.DateTime.Parse(dueDateTime); app_item.AllDayEvent = false; element.StartDate = startDate; element.DueDate = dueDate; } if (addToReminder) { app_item.Body = "Start date for " + element.NoteText + @" <file:\\" + element.Path + ">"; app_item.Subject = element.NoteText; app_item.ReminderMinutesBeforeStart = 0; app_item.Save(); app_item = null; } } if (addToTask) { task_item = outlook_app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem) as Microsoft.Office.Interop.Outlook.TaskItem; task_item.Subject = element.NoteText; task_item.Body = "Task for " + element.NoteText + " " + element.Path; if (hasStart) { task_item.StartDate = startDate; } if (hasDue) { task_item.DueDate = dueDate; } task_item.ReminderSet = false; task_item.Save(); task_item = null; } if (addToToday) { Element today = GetTodayElement(); if (today != null) { Element newElement = CreateNewElement(ElementType.Note, element.NoteText); InsertElement(newElement, today, 0); AddAssociation(newElement, element.Path, ElementAssociationType.FolderShortcut, null); Promote(newElement); Flag(newElement); /*if (hasStart) { if (isStartAllDay) { } else { newElement.NoteText += " Start: " + startDate.Month.ToString() + "/" + startDate.Day.ToString() + "/" + startDate.Year.ToString() + " " + startTime.Hour.ToString() + ":" + startTime.Minutes.ToString(); } } if (hasDue) { if (isDueAllDay) { } else { newElement.NoteText += " Due: " + dueDate.Month.ToString() + "/" + dueDate.Day.ToString() + "/" + dueDate.Year.ToString() + " " + dueTime.Hour.ToString() + ":" + dueTime.Minutes.ToString(); } }*/ } } Flag(element); }