FluentEmail icon indicating copy to clipboard operation
FluentEmail copied to clipboard

Add a way to specify Content-Type for alternate view

Open AndrewBoklashko opened this issue 7 years ago • 1 comments

Hi

I am rewriting my email notification service using FluentEmail and I have an ICal event in my email. Here is my original code:

private MailMessage CreateICalEventMessage(string email, string serializedCalendar)
            => new MailMessage(
                new MailAddress(_settings.EmailSender),
                new MailAddress(email))
            {
                Subject = "Event",
                IsBodyHtml = true,
                Body = "",
                AlternateViews =
                {
                    AlternateView.CreateAlternateViewFromString(
                        serializedCalendar,
                        new ContentType("text/calendar")
                        {
                            Parameters = { {"method", "REQUEST"} }
                        })
                }
            };

It seems like I can't achive this using FluentEmail, because default SmtpSender does not allow to set Content-Type.

https://github.com/lukencode/FluentEmail/blob/1f6cad81a0ee6314a81e4fc29873ae11d12b73a7/src/Senders/FluentEmail.Smtp/SmtpSender.cs#L92-L94

AndrewBoklashko avatar Aug 28 '18 16:08 AndrewBoklashko

I gave it some thoughts and ended up that the best solution would be to add additional parameter string contentType = null to alternate views API, exactly like in AttachFromFilename:

IFluentEmail PlaintextAlternativeBody(string body, string contentType = null);
IFluentEmail PlaintextAlternativeUsingTemplateFromEmbedded<T>(string path, T model, Assembly assembly, string contentType = null);
IFluentEmail PlaintextAlternativeUsingTemplateFromFile<T>(string filename, T model, string contentType = null);
IFluentEmail PlaintextAlternativeUsingCultureTemplateFromFile<T>(string filename, T model, CultureInfo culture, string contentType = null);
IFluentEmail PlaintextAlternativeUsingTemplate<T>(string template, T model, string contentType = null);

If this is acceptable for you, I can submit a pull request with an implementation.

AndrewBoklashko avatar Sep 01 '18 12:09 AndrewBoklashko