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

Fix mail header encoding issues with MimeKit #450

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chenseanxy
Copy link
Contributor

@chenseanxy chenseanxy commented Oct 22, 2024

Fixes #441, #317

Following recommendations in MimeKit's FAQ:

.NET Core (and ASP.NET Core by extension) and .NET 5 only provide the Unicode encodings, ASCII and ISO-8859-1 by default. Other text encodings are not available to your application unless your application registers the encoding provider that provides all of the additional encodings.
First, add a package reference for the System.Text.Encoding.CodePages nuget package to your project and then register the additional text encodings using the following code snippet:

System.Text.Encoding.RegisterProvider (System.Text.CodePagesEncodingProvider.Instance);

Note: The above code snippet should be safe to call in .NET Framework versions >= 4.6 as well.

@@ -150,6 +150,9 @@ protected override async void OnStartup(StartupEventArgs e)

if (isCreatedNew)
{
// Ensure proper encodings are available for MimeKit
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best place for this though, ideally this should be invoked before any Mailkit calls

@chenseanxy chenseanxy changed the title Fixes mail header encoding issues with MimeKit Fix mail header encoding issues with MimeKit Oct 22, 2024
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

Successfully merging this pull request may close these issues.

[Bug] Subject and other headers sometimes aren't in the right encoding
1 participant