private void InitializeMailMessage(MailMessage message, string emailViewOutput, Template template) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (template == null) { throw new ArgumentNullException(nameof(template)); } using (var reader = new StringReader(emailViewOutput)) { ParserUtils.ParseHeaders(reader, (key, value) => ProcessHeader(key, value, message, template)); AssignCommonHeaders(message, template); if (message.AlternateViews.Count == 0) { var messageBody = reader.ReadToEnd().Trim(); if (template.ImageEmbedder.HasImages) { var view = AlternateView.CreateAlternateViewFromString(messageBody, new ContentType("text/html")); template.ImageEmbedder.AddImagesToView(view); message.AlternateViews.Add(view); message.Body = "Plain text not available."; message.IsBodyHtml = false; } else { message.Body = messageBody; if (message.Body.StartsWith("<")) { message.IsBodyHtml = true; } } } AddAttachments(message, template as EmailTemplate); } }