/// <summary> /// Configures the <paramref name="emailMessage"/> according to the given <paramref name="messageConfiguration"/>. /// </summary> /// <param name="emailMessage">The email message to configure.</param> /// <param name="messageConfiguration">The message configuration to use.</param> /// <param name="objectContext">The object to use as context for any placeholder content.</param> public static void Configure ( this IEmailMessage emailMessage, MessageConfiguration messageConfiguration, ObjVerEx objectContext ) { // Sanity. if (null == emailMessage) { throw new ArgumentNullException(nameof(emailMessage)); } if (null == messageConfiguration) { throw new ArgumentNullException(nameof(messageConfiguration)); } if (null == objectContext) { throw new ArgumentNullException(nameof(objectContext)); } // To/CC/BCC. if (null != messageConfiguration.To) { foreach (var p in messageConfiguration.To) { emailMessage.AddRecipient(AddressType.To, p); } } if (null != messageConfiguration.CarbonCopy) { foreach (var p in messageConfiguration.CarbonCopy) { emailMessage.AddRecipient(AddressType.CarbonCopy, p); } } if (null != messageConfiguration.BlindCarbonCopy) { foreach (var p in messageConfiguration.BlindCarbonCopy) { emailMessage.AddRecipient(AddressType.BlindCarbonCopy, p); } } // Subject/email bodies. if (null != messageConfiguration.Subject) { emailMessage.Subject = objectContext.ExpandPlaceholderText(messageConfiguration.Subject); } if (null != messageConfiguration.TextBody) { emailMessage.TextBody = objectContext.ExpandPlaceholderText(messageConfiguration.TextBody); } if (null != messageConfiguration.HtmlBody) { emailMessage.HtmlBody = objectContext.ExpandPlaceholderText(messageConfiguration.HtmlBody); } // Override sender details? if (false == messageConfiguration.UseDefaultSender) { emailMessage.SetSender(messageConfiguration.From); } // Attach files? if (messageConfiguration.AttachCurrentObjectFiles) { emailMessage.AddAllFiles(objectContext, messageConfiguration.AttachedFileFormat); } }