MimeKit: NotSupportedException: No data is available for encoding 10000. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
public static void SendItemOptionAttachment(string from, string to, string subject, string bodyHtml, string attachment)
{
using var smtpSender = SmtpSender.Create(emailOptions.smtpHost)
.SetCredential(emailOptions.login, emailOptions.password);
var invalids = System.IO.Path.GetInvalidFileNameChars();
subject = String.Join("_", subject.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
MimeEntity mimeEntity = MimeEntity.Load(new ParserOptions() { CharsetEncoding = Encoding.UTF8 },new MemoryStream(Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes(attachment ?? "")).ToArray()));
from = emailOptions.fromName;
try
{
smtpSender.WriteEmail
.From(from)
.To(to)
.Subject(subject)
.BodyHtml(bodyHtml)
.Attach(mimeEntity)
.Send();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
This is one by ParserOptions method. MimeKit.dll!MimeKit.Utils.CharsetUtils.ProbeCharset(int codepage) crashes.
another one
.Attach(new MemoryStream(Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes(attachment ?? "")).ToArray()), $"{subject}_test.csv")
MimeKit.dll!MimeKit.Utils.CharsetUtils.ProbeCharset(int codepage) crashes.
How it can be disabled? This CSV file contains BOM with UTF8 to support Excel correct encoding on CSV files with UTF8.
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 18 (8 by maintainers)
@alexeik Because MimeKit needs it internally because it doesn’t know you are only going to need UTF-8.
MimeKit is meant to be able to parse and construct MIME for any real-world emails, so it needs access to all of the charsets regardless of what you personally want to use for creating new MIME messages.
It is extremely rare to only need UTF-8 when parsing real-world email messages.
@alexeik Please use the Copy Details and paste here the full exception with stack trace.