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); }
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 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; } }
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 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 + ""); }
public static string MoveEmailToFolder(string strMailbox, string strFolder1, string strFolder2, string strFolder3, string strItemEntryID, string strItemStoreID) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); int intFolderCount = 0; string strFolderFound = "N"; Outlook.MAPIFolder fldrsource = app.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent; string strLevel = ""; string strMoved = "N"; 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") { Outlook.MailItem themailitem = app.GetNamespace("MAPI").GetItemFromID(strItemEntryID, strItemStoreID); themailitem.Move(fldrsource); strMoved = "Y"; } return("" + strFolderFound + "|xxx|" + strMoved + ""); }
public static string ValidateFolder(string strMailbox, string strFolder1, string strFolder2, string strFolder3) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); int intFolderCount = 0; string strFolderFound = "N"; Outlook.MAPIFolder fldrsource = app.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent; 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; } } } return("" + strFolderFound + ""); }
static void Main(string[] args) { Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Outlook._NameSpace nameSpace = app.GetNamespace("MAPI"); nameSpace.Logon(null, null, false, false); Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts); Outlook.MailItem msg; //Making an Excel file Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Microsoft.Office.Interop.Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //Passing the files with address of msg file to StreamReader System.IO.StreamReader file = new System.IO.StreamReader(@"list_of_msg_files.txt"); const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; int count = 1; //In excel count starts from 1 string filePath, smtpAddress = ""; //reading name of each msg file from while ((filePath = file.ReadLine()) != null) { try { check++; msg = (Outlook.MailItem)app.Session.OpenSharedItem(filePath); } catch (Exception ex) { System.Console.WriteLine(filePath); if (check > 11093) { break; } else { continue; } } try { //Fiding Sender Information Outlook._MailItem temp = ((Outlook._MailItem)msg).Reply(); Outlook.Recipient sender = temp.Recipients[1]; Outlook.PropertyAccessor xx = sender.PropertyAccessor; try //For some companies, when an employee leaves, the local email address is deleted { smtpAddress = xx.GetProperty(PR_SMTP_ADDRESS).ToString(); } catch (Exception ex) { smtpAddress = "NAN"; } temp.Delete(); xlWorkSheet.Cells[count, 1] = (sender.Name == null) ? "" : sender.Name; } catch (Exception e) //ignore!! { xlWorkSheet.Cells[count, 1] = (msg.SenderName == null) ? "" : msg.SenderName; } xlWorkSheet.Cells[count, 2] = (smtpAddress == null) ? "" : smtpAddress; //subject xlWorkSheet.Cells[count, 3] = (msg.Subject == null) ? "" : msg.Subject; //Recipients smtpAddress = ""; string names = ""; Outlook.Recipients recips = msg.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string tmp; try // if email address is not there { tmp = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); } catch (Exception ex) { tmp = recip.Name; } smtpAddress = smtpAddress + "," + tmp; names = names + "," + recip.Name; } xlWorkSheet.Cells[count, 4] = (smtpAddress == null) ? "" : smtpAddress; xlWorkSheet.Cells[count, 5] = (names == null) ? "" : names; //In case you need CreationTime //xlWorkSheet.Cells[count, 6] = (msg.CreationTime == null) ? "" : msg.CreationTime.ToShortDateString(); //xlWorkSheet.Cells[count, 7] = (msg.ReceivedTime == null) ? "" : msg.ReceivedTime.ToShortDateString(); xlWorkSheet.Cells[count, 6] = (msg.SentOn == null) ? "" : msg.SentOn.Day + "-" + msg.SentOn.Month + "-" + msg.SentOn.Year; xlWorkSheet.Cells[count, 7] = (msg.Body == null) ? "" : msg.Body; xlWorkSheet.Cells[count, 8] = filePath; string attached = ""; for (int i = 0; i < msg.Attachments.Count; i++) { attached += "," + msg.Attachments[i + 1].FileName; } xlWorkSheet.Cells[count, 9] = attached; count++; } file.Close(); xlWorkBook.SaveAs("Emails.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); System.Console.ReadLine(); }
void Button2Click(object sender, EventArgs e) { DataTable dt3 = new DataTable(); DataTable dt5 = new DataTable(); SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=new_DB.sqlite;Version=3;"); m_dbConnection.Open(); string approved = "Ja"; string gridQuery1 = String.Format("UPDATE Urlaubsübersicht SET Genehmigt = '{0}' Where Antrags_ID = '{1}';", approved, ((DataTable)this.dataGridView1.DataSource).Rows[this.dataGridView1.SelectedCells[0].RowIndex]["Antrags_ID"] ); string gridQuery2 = String.Format("SELECT * FROM Urlaubsübersicht;"); SQLiteCommand command3 = new SQLiteCommand(gridQuery1, m_dbConnection); command3.ExecuteNonQuery(); SQLiteCommand command4 = new SQLiteCommand(gridQuery2, m_dbConnection); dt3.Load(command4.ExecuteReader()); string msg = String.Format("Row: {0}, Column: {1}", dataGridView1.CurrentCell.Value, dataGridView1.CurrentCell.ColumnIndex); // Telegram Message: WebClient client = new WebClient(); string who = dataGridView1.CurrentCell.Value.ToString(); string von = dataGridView1.CurrentRow.Cells[1].Value.ToString(); string bis = dataGridView1.CurrentRow.Cells[2].Value.ToString(); Stream s = client.OpenRead(String.Format("https://api.telegram.org/bot442786666:AAHPtI0yvYMdiYwkOg6mm9222JSm6AGTPBQ/sendMessage?chat_id=-244911442&text= Hallo Zusammen. Denkt bitte daran das {0} in der Zeit von {1} bis {2} Urlaub hat;", who, von, bis)); //this.dataGridView1.DataSource = dt3; // Email Microsoft.Office.Interop.Outlook.NameSpace lo_NSpace; Microsoft.Office.Interop.Outlook.MAPIFolder lo_Folder; Microsoft.Office.Interop.Outlook.Application lo_OutApp; Microsoft.Office.Interop.Outlook.MailItem lo_Item; lo_OutApp = new Microsoft.Office.Interop.Outlook.Application(); lo_NSpace = lo_OutApp.GetNamespace("MAPI"); lo_Folder = lo_NSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail); lo_Item = (Microsoft.Office.Interop.Outlook.MailItem)lo_Folder.Items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); lo_Item.To = who; lo_Item.Subject = "Urlaub"; lo_Item.Body = "Hallo " + who + " ich habe deinen Urlaub in der Zeit vom " + von + " bis " + bis + " genehmigt."; //NachrichtenFormat lo_Item.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText; //Anzeigen modal lo_Item.Display(true); //Senden der Mail lo_Item.Send(); }