Update 2021.03.05: Seems like this doesn't happen with .net 4.8 (application or fsi) But always happen with .net 5.0 (application and fsi)
https://github.com/ingted/dotnet5mail
It is very weird that if I execute this code with .net4.8, the email would successfully be sent but not with .net 5.0. (It would say "Unhandled exception. System.AggregateException: One or more errors occurred. (The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.")
System.Net.Mail.SmtpClient()
is obsolete in .NET 5.
SmtpClient has been obsolete since I believe .NET Core 2.0 and .NET 5 is more closely a progression of .NET Core 3.1, not a progression of .NET Framework 4.8.
REF: https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-5.0
Microsoft recommends switching to MailKit.
Nuget Link