// Récupération des informations du mail private void getSelectedItem(CommandBarButton Ctrl, ref bool CancelDefault) { try { // Récupération de l'item sélectionné Outlook.MailItem item = (Outlook.MailItem)outlook.ActiveExplorer().Selection[1]; //Récupération du store ID Outlook.MAPIFolder store = (Outlook.MAPIFolder)item.Parent; // Création du PropertyAccessor Outlook.PropertyAccessor props = item.PropertyAccessor; // Déclenchement de l'event NewMail OnNewMail(new NewMailEventArgs(item.Subject, store.StoreID, item.EntryID, (String)props.GetProperty(this.messageIDParam))); Marshal.FinalReleaseComObject(props); Marshal.FinalReleaseComObject(store); Marshal.FinalReleaseComObject(item); } catch (System.Runtime.InteropServices.COMException e) { // On affiche l'erreur TrayIcon.afficheMessage("Exception sur récupération Outlook", e.Message + "\n" + e.ErrorCode.ToString()); } }
/// <summary> /// Finds the Global Address List associated with the MailStore /// </summary> /// <returns>OLAddressList for GAL or null if store has no GAL</returns> public IAddressBook GetGlobalAddressList() { string PR_EMSMDB_SECTION_UID = @"http://schemas.microsoft.com/mapi/proptag/0x3D150102"; if (_store == null) { throw new ArgumentNullException(); } Outlook.PropertyAccessor oPAStore = _store.PropertyAccessor; string storeUID = oPAStore.BinaryToString(oPAStore.GetProperty(PR_EMSMDB_SECTION_UID)); foreach (Outlook.AddressList addrList in _store.Session.AddressLists) { Outlook.PropertyAccessor oPAAddrList = addrList.PropertyAccessor; string addrListUID = oPAAddrList.BinaryToString(oPAAddrList.GetProperty(PR_EMSMDB_SECTION_UID)); // Returns addrList if match on storeUID // and type is olExchangeGlobalAddressList. if (addrListUID == storeUID && addrList.AddressListType == Outlook.OlAddressListType.olExchangeGlobalAddressList) { return(new AddressBookProviderOM(addrList)); } } return(null); }
private static string GetHeader(Outlook.MailItem item, string headerName) { Outlook.PropertyAccessor accessor = null; try { accessor = item.PropertyAccessor; return(accessor.GetProperty(headerName)); } catch (System.Runtime.InteropServices.COMException ex) { Debug.WriteLine("GetHeader: Failed to retreive header, this is expected behaviour when the header is not present: " + ex.ToString()); } catch (System.Exception ex) { Debug.WriteLine("GetHeader: Unexpected error retrieving header: " + ex.ToString()); } finally { if (accessor != null) { Marshal.ReleaseComObject(accessor); } } return(null); }
void items_ItemAdd(object Item) { Outlook.MailItem mail = (Outlook.MailItem)Item; try { MailServiceReference.MailServiceClient mailServiceObj = new MailServiceReference.MailServiceClient(); if (Item != null) { string filterSenderMailID = mailServiceObj.GetTargetMailId(); const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); if (smtpAddress.ToLower() == filterSenderMailID.ToLower()) { mailServiceObj.InsertMailBody(mail.SenderEmailAddress, mail.ReceivedByName, mail.Subject, mail.Body); break; } } } } catch (Exception ex) { System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog(); appLog.Source = "Claysys UCU Outlook plugging"; appLog.WriteEntry("Exception : " + ex); throw ex; } }
public void Button_Click(Office.IRibbonControl control) { try { Outlook.Recipient recipient = null; Outlook.Recipients recipients = null; Outlook.Application application = new Outlook.Application(); Outlook.Explorer explorer = application.ActiveExplorer(); Outlook.Inspector inspector = application.ActiveInspector(); inspector.Activate(); Outlook._MailItem mailItem = inspector.CurrentItem; //Outlook.Application outlookApplication = new Outlook.Application(); //Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem; if (mailItem != null) { recipients = mailItem.Recipients; recipients.ResolveAll(); String StrR = ""; const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; foreach (Outlook.Recipient recip in recipients) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); string[] strsplit = smtpAddress.Split('@'); if (!StrR.Contains(strsplit[1])) { StrR += strsplit[1] + Environment.NewLine; } } if (StrR != string.Empty) { MyMessageBox ObjMyMessageBox = new MyMessageBox(); ObjMyMessageBox.ShowBox(StrR); } //recipient.Resolve(); // DialogResult result = MessageBox.Show("Are you sure you want to send emails to the following domains " + StrR, "Varify Domains ", //MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); // if (result == DialogResult.Yes) // { // //code for Yes // } // else // { // } } } catch (Exception ex) { } }
public static string EmailAddressesStr(Outlook.MailItem email, bool incML = false) { //find the client from e-mail //collect all the email addressess. string emails = email.SenderEmailAddress; const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; foreach (Outlook.Recipient rec in email.Recipients) { Outlook.PropertyAccessor pa = rec.PropertyAccessor; string s = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); s = s.ToLower(); if (!incML) { if (!s.Contains("milstedlangdon")) { emails += ";" + pa.GetProperty(PR_SMTP_ADDRESS).ToString(); } } } //Remove any unwanted ' emails = emails.Replace("'", ""); return(emails); }
private static void NameSortStores(Outlook.Application OA) { NameSpace S = OA.Session; for (int yrs = 2000; yrs < 2019; yrs++) { String PST_displayName = String.Format("{0}-00-00", yrs.ToString("0000")); Store St = GetStore(S, PST_displayName); if (St == null) { continue; } Folder rF = St.GetRootFolder() as Folder; rF.Name = PST_displayName; Outlook.PropertyAccessor pA = St.PropertyAccessor; dynamic P = pA.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3001001E"); //pA.SetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3001001E", PST_displayName); rF.ShowItemCount = OlShowItemCount.olShowTotalItemCount; Folder a = null; if (OutlookFolderExists(rF.Folders, "Inbox")) { a = GetFolder(rF, "Inbox"); } else { a = rF.Folders.Add("Inbox") as Outlook.Folder; } CreateMonthSubfolders(a); } }
private bool checkIfInline(Outlook.Attachment att) { switch (att.Type) { case Outlook.OlAttachmentType.olEmbeddeditem: case Outlook.OlAttachmentType.olByReference: case Outlook.OlAttachmentType.olOLE: return(true); } Outlook.PropertyAccessor prop = att.PropertyAccessor; object emCID = prop.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E"); string emMime = (prop.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001E") != null ? att.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001E").ToString() : ""); if (!att.Type.Equals(Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE) && (!emMime.ToLower().Contains("image") || (emCID == null || (emCID.Equals(""))))) { return(true); } if (prop.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3713001E") is null || prop.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37140003") == 4) { return(true); } return(false); }
internal static void SetProperty(this Outlook.MailItem _mailItem, string _propertyName, object _value) { if (_mailItem == null) { throw new ArgumentNullException(); } Outlook.PropertyAccessor propertyAccessor = null; try { propertyAccessor = _mailItem.PropertyAccessor; if (propertyAccessor != null) { propertyAccessor.SetProperty(_propertyName, _value); } } catch (COMException) { } finally { if (propertyAccessor != null) { Marshal.ReleaseComObject(propertyAccessor); propertyAccessor = null; } } }
public static string GetMailItemHeaderItem(Outlook.MailItem mailItem, Regex regex) { if (mailItem == null) { return(string.Empty); } string TransportMessageHeadersSchema = "http://schemas.microsoft.com/mapi/proptag/0x007D001E", header = string.Empty; try { if (mailItem.PropertyAccessor != null) { Outlook.PropertyAccessor propertyAccessor = mailItem.PropertyAccessor; header = (string)propertyAccessor.GetProperty(TransportMessageHeadersSchema); } Match match = regex.Match(header); header = match.Success ? match.Value.Trim() : string.Empty; } catch (Exception eException) { header = eException.Message; } return(header); }
public static string GetMailHeader(Outlook.PropertyAccessor prop) { const string PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"; string headerString = (string)prop.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS); System.Runtime.InteropServices.Marshal.ReleaseComObject(prop); return(headerString); }
public void SetProperties(string[] properties, object[] values) { NSOutlook.PropertyAccessor props = GetPropertyAccessor(); try { props.SetProperties(properties, values); } finally { ComRelease.Release(props); } }
public void SetProperty(string property, object value) { NSOutlook.PropertyAccessor props = GetPropertyAccessor(); try { props.SetProperty(property, value); } finally { ComRelease.Release(props); } }
/// <summary> /// Sets the mail item property /// </summary> /// <param name="item"></param> /// <param name="propName"></param> /// <param name="value"></param> private void SetMailItemProperty(Outlook.MailItem item, string propName, object value) { try { Outlook.PropertyAccessor accessor = item.PropertyAccessor; accessor?.SetProperty(propName, value); } catch (Exception ex) { //[SF] Don't re-throw any error ex.GetType(); } }
private bool DeleteMailItemProperty(Outlook.MailItem item, string propName) { try { Outlook.PropertyAccessor accessor = item.PropertyAccessor; accessor.DeleteProperty(propName); } catch (System.Exception ex) { //[SF] Don't re-throw any error ex.GetType(); return(false); } return(true); }
private void CreateMailItem(Outlook.MailItem selectedItem) { Outlook.PropertyAccessor olPA = selectedItem.PropertyAccessor; string header = olPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS); string spamDomain = selectedItem.SenderEmailAddress.Split('@')[1]; POCO response = JsonConvert.DeserializeObject <POCO>(GetAbuseEmail(spamDomain)); Outlook.MailItem mailItem = (Outlook.MailItem) Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem); mailItem.Subject = "Spam Abuse from: " + spamDomain; mailItem.To = response.data["email"]; mailItem.Body = GetBody(selectedItem.Body, header, spamDomain); mailItem.Importance = Outlook.OlImportance.olImportanceLow; mailItem.Display(false); }
private void testForm_Load(object sender, EventArgs e) { initComoBoxes(); const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; txtMailBody.Text = mailItem.Body; txtMailSybject.Text = mailItem.Subject; foreach (Outlook.Recipient recipeint in mailItem.Recipients) { string smtpAddress = ""; if (recipeint.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || recipeint.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) { Outlook.PropertyAccessor pa = recipeint.PropertyAccessor; smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); } else { smtpAddress = recipeint.Address; } txtRecipient.Text += smtpAddress + ";"; } DateTime creationTime = mailItem.CreationTime; txtDateTimeCreated.Text = creationTime.ToString(@"dd.MM.yyy HH:mm:ss"); //Outlook.PropertyAccessor pa2 = mailItem.Sender.PropertyAccessor; string smtpAddressAuthor = ""; if (mailItem.Sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || mailItem.Sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) { Outlook.ExchangeUser exchUser = mailItem.Sender.GetExchangeUser(); if (exchUser != null) { smtpAddressAuthor = exchUser.PrimarySmtpAddress; } } else { smtpAddressAuthor = mailItem.Sender.Address; } txtAuthor.Text = smtpAddressAuthor; }
/// <summary> /// Gets the mail item property /// </summary> /// <param name="item"></param> /// <param name="propName"></param> /// <returns></returns> private object GetMailItemProperty(Outlook.MailItem item, string propName) { object value = null; try { Outlook.PropertyAccessor accessor = item.PropertyAccessor; value = accessor.GetProperty(propName); } catch (System.Exception ex) { //[SF] Don't re-throw any error ex.GetType(); } return(value); }
private void CurrentExplorer_Event() { Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder; String itemMessage = null; const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; try { if (this.Application.ActiveExplorer().Selection.Count > 0) { Object selObject = this.Application.ActiveExplorer().Selection[1]; if (selObject is Outlook.AppointmentItem) { Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem); Outlook.Recipients recips = apptItem.Recipients; string str = null; foreach (Outlook.Recipient recip in recips) { if (recip.MeetingResponseStatus != Outlook.OlResponseStatus.olResponseAccepted) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); str += smtpAddress + ";"; } } if (str != null) { itemMessage = str; MessageBox.Show("Not responded: " + itemMessage); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
private static List <string> GetSMTPAddressForRecipients(Outlook.MailItem mail) { List <string> recepients = new List <string>(); const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); //stringBuilder.AppendLine(recip.Name + " SMTP=" + smtpAddress); recepients.Add(smtpAddress); } return(recepients); }
private static void SetHeader(Outlook.MeetingItem item, string headerName, string headerValue) { Outlook.PropertyAccessor accessor = null; try { accessor = item.PropertyAccessor; accessor.SetProperty(headerName, headerValue); } finally { if (accessor != null) { Marshal.ReleaseComObject(accessor); } } }
void MailItemHeaderShow(Outlook.MailItem mailItem) { if (mailItem == null) { return; } System.Windows.Forms.TextBox tmpTextBox; if ((tmpTextBox = myUserControl1.Controls["textBox1"] as System.Windows.Forms.TextBox) != null) { //http://blogs.msdn.com/b/zainnab/archive/2008/07/01/using-visual-studio-2008-vsto-outlook-to-pull-out-rfc-822-header-data.aspx //http://www.lessanvaezi.com/email-headers-from-outlook-mailitem/ string TransportMessageHeadersSchema = "http://schemas.microsoft.com/mapi/proptag/0x007D001E", // TransportMessageHeadersSchema = "http://schemas.microsoft.com/mapi/proptag/0x007D001F", // 4 Unicode header = string.Empty; try { if (mailItem.PropertyAccessor != null) { Outlook.PropertyAccessor propertyAccessor = mailItem.PropertyAccessor; header = (string)propertyAccessor.GetProperty(TransportMessageHeadersSchema); } Regex r = new Regex("(?<=From:.*?<).*?(?=>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match match = r.Match(header); header = match.Success ? match.Value : string.Empty; } catch (Exception eException) { header = eException.Message; } tmpTextBox.Text = header; } }
public static void SetDefaultFormOnFolder(Outlook.MAPIFolder mapiFolder, string formName, string formClass) { string prDefMsgClass = "http://schemas.microsoft.com/mapi/proptag/0x36E5001E"; string prDefFormName = "http://schemas.microsoft.com/mapi/proptag/0x36E6001E"; try { Outlook.PropertyAccessor propertyAccessor = mapiFolder.PropertyAccessor; propertyAccessor.SetProperty(prDefMsgClass, formClass); propertyAccessor.SetProperty(prDefFormName, formName); Marshal.ReleaseComObject(propertyAccessor); } catch (Exception exception) { Console.WriteLine("Unable to set the default form. Error: " + exception.ToString()); } }
/// <summary> /// Loads the namespaces into memory /// </summary> private void LoadNamespaceInfo() { int iCount = 0; // for namespaces // build and create a list of namespaces for each account loaded in Outlook // what we will do is create an entry for every account since we do not know if // which one the add-in is loaded in. It could be one, or all MobjAccountUIDs = new Dictionary <string, string>(); // loop through each account and add a ribbon NS element for each one foreach (Outlook.Account account in Globals.ThisAddIn.Application.Session.Accounts) { iCount++; Outlook.PropertyAccessor propertyAccessor = account.CurrentUser.PropertyAccessor; string ns = "x" + iCount.ToString(); MobjAccountUIDs.Add(ns, MstrWebAddinID + "_" + propertyAccessor.BinaryToString(propertyAccessor.GetProperty(PR_EMSMDB_SECTION_UID))); break; } }
public object GetProperty(string property) { NSOutlook.PropertyAccessor props = GetPropertyAccessor(); try { object val = props.GetProperty(property); if (val is DBNull) { return(null); } return(val); } catch (System.Exception) { return(null); } finally { ComRelease.Release(props); } }
public void dgvGetSMTPAddressForRecipients(DataGridView dgv) { const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); DataGridViewRow dgvr = new DataGridViewRow(); dgvr.CreateCells(dgv); dgvr.Cells[0].Value = recip.Name; dgvr.Cells[1].Value = smtpAddress; dgv.Rows.Add(dgvr); //Debug.WriteLine(recip.Name + " SMTP=" + smtpAddress); } }
private void ThisApplication_NewMail() { Outlook.MAPIFolder inBox = this.Application.ActiveExplorer() .Session.GetDefaultFolder(Outlook .OlDefaultFolders.olFolderInbox); Outlook.Items inBoxItems = inBox.Items; Outlook.MailItem newEmail = null; inBoxItems = inBoxItems.Restrict("[Unread] = true"); try { foreach (object collectionItem in inBoxItems) { newEmail = collectionItem as Outlook.MailItem; Outlook.PropertyAccessor objPA = null; byte[] varX; //Dynamic if (newEmail != null) { if (newEmail.Attachments.Count > 0) { for (int i = 1; i <= newEmail.Attachments.Count; i++) { newEmail.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + newEmail.Attachments[i].FileName); objPA = newEmail.Attachments[i].PropertyAccessor; varX = objPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37010102"); //newEmail.Attachments.Add( } } } } } catch (System.Exception ex) { string errorInfo = (string)ex.Message .Substring(0, 11); if (errorInfo == "Cannot save") { MessageBox.Show(@"Create Folder C:\TestFileSave"); } } }
//http://msdn.microsoft.com/en-us/library/office/ff184647.aspx private void GetSMTPAddressForRecipients(Outlook.MailItem mail) { const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; recips.ResolveAll(); foreach (Outlook.Recipient recip in recips) { try { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); //if (!emails.Keys.Contains(smtpAddress)) emails.Add(smtpAddress, recip.Name ); SaveRecipient(smtpAddress, recip.Name); SetSenderSubject(smtpAddress, mail.Subject); } catch (Exception ex) { } } }
private String GetSMTPAddressForRecipients(Outlook.MailItem mail) { string smtpAddress = string.Empty; try { const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; smtpAddress = smtpAddress + " " + pa.GetProperty(PR_SMTP_ADDRESS).ToString(); } smtpAddress = smtpAddress.Trim(); } catch (Exception e) { Console.WriteLine(e.Message); } return(smtpAddress); }
private Outlook.AddressList GetGlobalAddressList(Outlook.Application outlookApp, Outlook.Store store) { // Property string for the UID of a store or address list. string PR_EMSMDB_SECTION_UID = @"http://schemas.microsoft.com/mapi/proptag/0x3D150102"; if (store == null) { throw new ArgumentNullException(); } // Obtain the store UID using the proprety string and // property accessor on the store. Outlook.PropertyAccessor oPAStore = store.PropertyAccessor; // Convert the store UID to a string value. string storeUID = oPAStore.BinaryToString(oPAStore.GetProperty(PR_EMSMDB_SECTION_UID)); // Enumerate each address list associated // with the session. foreach (Outlook.AddressList addrList in outlookApp.Session.AddressLists) { // Obtain the address list UID and convert it to // a string value. Outlook.PropertyAccessor oPAAddrList = addrList.PropertyAccessor; string addrListUID = oPAAddrList.BinaryToString(oPAAddrList.GetProperty(PR_EMSMDB_SECTION_UID)); // Return the address list associated with the store // if the address list UID matches the store UID and // type is olExchangeGlobalAddressList. if (addrListUID == storeUID && addrList.AddressListType == Outlook.OlAddressListType.olExchangeGlobalAddressList) { return(addrList); } } return(null); }