Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FluentEmail.AttachFromFileName({fileName}, "content-type", "attachmentName") has "Content-Type" as optional but is ideally expected. Throws error #383

Open
aravindk777 opened this issue Feb 29, 2024 · 1 comment

Comments

@aravindk777
Copy link

Currently, the method AttachFromFileName({fileName}, {Content-Type}, {attachmentName}) has only fileName as required and other two including "content-type" as optional. But in the implementation, it seems its expected/required. When i implemented the attachment option with just the fileName parameter only, it throws error

Value cannot be null. (Parameter name 'text')

When i dig deeper into the source code of this, I found like its been expected to parse further down, as ContentType.Parse(text).

Either, make the "content-type" parameter as required or dont expect it further down the line, may be, derive the content type implicitly or auto detect, whichever could solve not to throw such error.

Stack trace details:

at MimeKit.Utils.ParseUtils.ValidateArguments(ParserOptions options, String text)
at MimeKit.ContentType.Parse(ParserOptions options, String text)
at MimeKit.ContentType.Parse(String text)
at FluentEmail.MailKitSmtp.MailKitSender.<>c__DisplayClass5_0.b__0(Attachment x)
at FluentEmail.Core.ListExtensions.ForEach[T](IEnumerable1 enumerable, Action1 consumer)
at FluentEmail.MailKitSmtp.MailKitSender.CreateMailMessage(IFluentEmail email)
at FluentEmail.MailKitSmtp.MailKitSender.d__3.MoveNext()

My code usage/implementation is,

if (File.Exists(file))
{                  
    mailer.AttachFromFilename(file, attachmentName: Path.GetFileName(file));
}
@asherber
Copy link

I think it's actually MimeKit which expects the content type, not this library. The classes in this library are designed to be generic and to work with multiple senders; for example, SmtpSender, which uses the built-in SmtpClient, does not need a content type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants