Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send an email with attachments using SmtpClient.SendAsync?

People also ask

How do I send an email with an attachment in .NET core?

Credentials – Valid login credentials for the SMTP server (Gmail: email address and password). Port – Port Number of the SMTP server (Gmail: 587). When the Form is submitted, the posted values are captured through the EmailModel class object. All the fetched values are set into an object of the MailMessage class.

What can I use instead of SmtpClient?

The SMTP protocol is defined in RFC 2821, which is available at https://www.ietf.org. We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit or other libraries instead.


Don't use "using" here. You are destroying the memory stream immediately after calling SendAsync, e.g. probably before SMTP gets to read it (since it's async). Destroy your stream in the callback.