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 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()); } }
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 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); } } }
private void SendMassMail() { string fileLogo = Configuration.DeriveFileNameFromPath(configuration.Logo); string fileBackground = Configuration.DeriveFileNameFromPath(configuration.Background); if (Configuration.DoesPathExist(configuration.Logo) && Configuration.DoesPathExist(configuration.Background)) { //Make Font object in order to derive user-selected properties Font font = (Font) new FontConverter().ConvertFromString(configuration.Font); Outlook.MailItem mail = (Outlook.MailItem) this.Application.CreateItem(Outlook.OlItemType.olMailItem); AddRecipients(mail); mail.Subject = MAIL_SUBJECT; Outlook.Attachment logo = mail.Attachments.Add(configuration.Logo, Outlook.OlAttachmentType.olEmbeddeditem, 0, "<logo.jpg>"); Outlook.Attachment background = mail.Attachments.Add(configuration.Background, Outlook.OlAttachmentType.olEmbeddeditem, 0, "<background.jpg>"); string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E"; Outlook.PropertyAccessor logoProperties = mail.Attachments[1].PropertyAccessor; Outlook.PropertyAccessor backgroundProperties = mail.Attachments[2].PropertyAccessor; logoProperties.SetProperty(SchemaPR_ATTACH_CONTENT_ID, "<logo.jpg>"); backgroundProperties.SetProperty(SchemaPR_ATTACH_CONTENT_ID, "<background.jpg>"); mail.HTMLBody = "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.0 Transitional//EN\"><HTML><BODY background='cid:background.jpg' ><IMG alt=\"\" src='cid:logo.jpg' /><FONT color=" + configuration.Color + " size=\"" + font.SizeInPoints + "\" face=\"" + font.OriginalFontName + "\"><P><STRONG>" + MAIL_SUBJECT + "</STRONG></P><P>" + HintOfTheDay.Generate() + "</P></FONT></BODY></HTML>"; mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML; mail.Display(false); } else { ShowError(ERROR_IMAGES_NOT_FOUND); } }