Overview
TheMailsController provides functionality for sending emails using SMTP. It retrieves email server configuration from IConfiguration including credentials, host, port, and SSL settings.
Constructor
MailsController
Initializes a new instance of the controller with configuration access.Configuration service for accessing mail server settings and credentials
/workspace/source/MvcCoreUtilidades/Controllers/MailsController.cs:11
Methods
SendMail (GET)
Displays the email composition form.Returns the SendMail view
/workspace/source/MvcCoreUtilidades/Controllers/MailsController.cs:16
SendMail (POST)
[HttpPost] Sends an email asynchronously using SMTP with configuration from appsettings.The recipient email address
The email subject
The email message body (supports HTML)
Returns the SendMail view with ViewData containing:
MENSAJE: “Mensaje enviado correctamente.” on success
MailSettings:Credentials:User- Sender email addressMailSettings:Credentials:Password- Email account passwordServer:Host- SMTP server hostnameServer:Port- SMTP server portServer:Ssl- Enable/disable SSLServer:DefaultCredentials- Use default credentials flag
- Creates a
MailMessagewith HTML body and normal priority - Configures
SmtpClientwith settings from configuration - Important: Sets
UseDefaultCredentialsBEFORE setting custom credentials - Sends the email asynchronously
- Returns success message in ViewData
/workspace/source/MvcCoreUtilidades/Controllers/MailsController.cs:21