Applica.Emailing 0.1.2

dotnet add package Applica.Emailing --version 0.1.2
                    
NuGet\Install-Package Applica.Emailing -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Applica.Emailing" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Applica.Emailing" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Applica.Emailing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Applica.Emailing --version 0.1.2
                    
#r "nuget: Applica.Emailing, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Applica.Emailing@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Applica.Emailing&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Applica.Emailing&version=0.1.2
                    
Install as a Cake Tool

Applica.Emailing

NuGet NuGet Downloads

Librería de C# (.NET 8) para envío de correos vía SMTP con MailKit.

  • Diseño: SOLID, namespaces con file-scope, constructores primarios y ⇐ 3 argumentos por método.
  • DI: extensiones para IServiceCollection.
  • Seguridad: no expone secretos en código; use variables de entorno o gestores de secretos.
  • Autenticación recomendada (por defecto): OAuth 2.0 (XOAUTH2) para Gmail con scope https://mail.google.com/.

Instalación (proyecto consumidor)

Paquete NuGet publicado: https://www.nuget.org/packages/Applica.Emailing Instalar con dotnet CLI:

dotnet add package Applica.Emailing

o agregar en tu .csproj (permitir parches dentro de la serie 0.1.x):

<ItemGroup>
  <PackageReference Include="Applica.Emailing" Version="0.1.*" />
</ItemGroup>
  1. Referencie el paquete/proyecto Applica.Emailing.
  2. Configure SMTP por código o por configuración.

Opción recomendada: OAuth2 (Gmail XOAUTH2)

Ejemplo de appsettings.Development.json (credenciales en variables de entorno/secret manager; no en git):

{ "GmailOAuth": { "ClientId": "{{GOOGLE_CLIENT_ID}}", "ClientSecret": "{{GOOGLE_CLIENT_SECRET}}", "RefreshToken": "{{GOOGLE_REFRESH_TOKEN}}" }, "Emailing": { "Host": "smtp.gmail.com", "Port": 587, "UseSsl": true, "Username": "tu-cuenta@gmail.com", "AuthMode": "OAuth2", "DefaultFrom": { "Address": "tu-cuenta@gmail.com", "DisplayName": "Notificaciones" } } }

Registro en DI con AccessTokenFactory (requiere el paquete Google.Apis.Auth en TU proyecto consumidor):

services.AddEmailing(opts ⇒ { var gmail = configuration.GetSection("GmailOAuth"); var flow = new Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow( new Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new Google.Apis.Auth.OAuth2.ClientSecrets { ClientId = gmail["ClientId"], ClientSecret = gmail["ClientSecret"] } });

opts.Host = "smtp.gmail.com";
opts.Port = 587;
opts.UseSsl = true; // STARTTLS
opts.AuthMode = Applica.Emailing.Implementations.Smtp.SmtpAuthMode.OAuth2;
opts.Username = configuration["Emailing:Username"]; // debe ser tu-cuenta@gmail.com
opts.DefaultFrom = new Applica.Emailing.Models.EmailAddress(configuration["Emailing:Username"], "Notificaciones");

opts.AccessTokenFactory = async ct =>
{
    var token = new Google.Apis.Auth.OAuth2.Responses.TokenResponse { RefreshToken = gmail["RefreshToken"] };
    var cred = new Google.Apis.Auth.OAuth2.UserCredential(flow, "user", token);
    return await cred.GetAccessTokenForRequestAsync("https://mail.google.com/", ct);
};

});

Ver guía paso a paso en docs/HELP_GMAIL.md.

Alternativa: App Password (Gmail)

{ "Emailing": { "Host": "smtp.gmail.com", "Port": 587, "UseSsl": true, "Username": "tu-cuenta@gmail.com", "Password": "{{GMAIL_APP_PASSWORD}}", "DefaultFrom": { "Address": "tu-cuenta@gmail.com", "DisplayName": "Notificaciones" } } }

services.AddEmailing(configuration, "Emailing");

Enviar correo

var sender = serviceProvider.GetRequiredService<Applica.Emailing.Abstractions.IEmailSender>(); var msg = new Applica.Emailing.Models.EmailMessage(new Applica.Emailing.Models.EmailMessageData { To = new[]{ new Applica.Emailing.Models.EmailAddress("destinatario@example.com", "Destinatario") }, Subject = "Hola", BodyText = "Hola mundo (texto)", BodyHtml = "<p>Hola mundo</p>" }); await sender.SendAsync(msg);

Notas

  • Scope para XOAUTH2 SMTP: https://mail.google.com/.
  • Cumple la regla de ⇐ 3 parámetros por método.
  • Sin git add/commit automáticos; sólo git init.
  • .NET 8; si desea NET9, cambie el target framework en el csproj.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 84 9/26/2025
0.1.1 79 9/26/2025
0.1.0 83 9/26/2025