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

[API Proposal]: Customized date formatting for SmtpClient #110361

Open
NXTwoThou opened this issue Dec 3, 2024 · 3 comments
Open

[API Proposal]: Customized date formatting for SmtpClient #110361

NXTwoThou opened this issue Dec 3, 2024 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@NXTwoThou
Copy link

Background and motivation

I've had a long term issue with the built in mail app on my phone(Xiaomi) for a number of years. Any email sent via .NET shows 12/31/1969 for the date. I'm inbetween projects for a few hours this morning and it finally bugged me enough to look into it. So I turned on debug logging on our mail server and captured a few hundred emails from various sources this morning and directly ran some sets with .NET Framework 4.8 and .NET 9.

The likely cause of the issue with Xiaomi's mail app is the format used by the date. I don't think they understood RFC822 where the day of the week is an optional field([]).

Out of the 128 emails I parsed in the logs, the only one not sending the DOW is .NET. Is there some flag I'm missing?

For example, I sent an email to my Outlook email from a .NET 9 WinForm app:

Date: 3 Dec 2024 09:26:24 -0600

I then replied to that email from Outlook.com and got back

Date: Tue, 3 Dec 2024 15:36:32 +0000

I recognize I don't have an issue viewing the non-DOW formatted date with Thunderbird, Outlook client, Outlook.com, Yahoo mail, and GMail. I recognize 128 emails is a pretty small sampling, but if everyone else is doing it, could it be an option to turn on for additional compatibility?

API Proposal

enum SmtpDateFormatting { Standard,Full };
public DateFormatting=SmtpDateFormatting.Standard;

string tz=date.ToString("zzz").Replace(":","");
if(DateFormatting==SmtpDateFormatting.Full)
return date.ToString("ddd, d MMM yyyy HH:mm:ss ")+tz;
else
return date.ToString("d MMM yyyy HH:mm:ss ")+tz;

API Usage

SmtpClient.DateFormatting=SmtpDateFormatting.Full;

Alternative Designs

No response

Risks

No response

@NXTwoThou NXTwoThou added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 3, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 3, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 3, 2024
@Tornhoof
Copy link
Contributor

Tornhoof commented Dec 3, 2024

The integrated SMTPClient is deprecated.
See https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-9.0

A modern replacement is Mailkit
https://github.com/jstedfast/MailKit

@vcsjones vcsjones changed the title [API Proposal]: [API Proposal]: Customized date formatting for SmtpClient Dec 3, 2024
@vcsjones vcsjones added area-System.Net and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 3, 2024
@wfurt
Copy link
Member

wfurt commented Dec 3, 2024

MailMessage exposes Headers collection. Did you try to set it directly @NXTwoThou?
@Tornhoof is right that the class is in maintenance only mode and it is unlikely we would extend it at the moment.

@wfurt wfurt added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels Dec 3, 2024
@wfurt wfurt added this to the Future milestone Dec 3, 2024
@NXTwoThou
Copy link
Author

MailMessage exposes Headers collection. Did you try to set it directly @NXTwoThou? @Tornhoof is right that the class is in maintenance only mode and it is unlikely we would extend it at the moment.

The first thing I did was hunt to see if I could directly set it. https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage.headers?view=netframework-4.8 has a long list of headers that are discarded if you try to directly set them. Including Date

@dotnet-policy-service dotnet-policy-service bot added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

4 participants