Prosmart.CoreMailer 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Prosmart.CoreMailer --version 1.0.0
NuGet\Install-Package Prosmart.CoreMailer -Version 1.0.0
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="Prosmart.CoreMailer" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Prosmart.CoreMailer --version 1.0.0
#r "nuget: Prosmart.CoreMailer, 1.0.0"
#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.
// Install Prosmart.CoreMailer as a Cake Addin
#addin nuget:?package=Prosmart.CoreMailer&version=1.0.0

// Install Prosmart.CoreMailer as a Cake Tool
#tool nuget:?package=Prosmart.CoreMailer&version=1.0.0

CoreMailer for NET Core 3.1 and above

Based on Riyasat CoreMailer project, this package is meant to work with NET Core 3.1 LTS and above. Send emails from dynamic templates made with Razor.

IMPORTANT If you are using NET Core 3.1 and above you must configure your Startup.cs services to work with controllers & views, specially if the project was bootstraped to be a Razor Web App. Here we are using controllers & views to generate email views. More instructions below.

How to Use

Installation

Add package reference to your project .csproj file. For more installation methods refer to the package NuGet site.

<PackageReference Include="prosmart.CoreMailer" Version="1.0.0" />

Usage

In Startup.cs, ConfigureServices

TemplateRenderer & CoreMvcmailer services must be cregistered as scoped services.

REMEMBER as per docs of NET Core 3.x, MVC Registration had some changes. If you are using a Razor Page project or WebAPI-only you must register controllers & views in order to use this package. So, the final service registration section would be like this:

services.AddScoped<ITemplateRenderer, TemplateRenderer>();
services.AddScoped<ICoreMvcMailer, CoreMvcMailer>();
services.AddControllersWithViews();

You can use this MVC Registration alongside Razor Pages, read the docs provided to understand these changes.

Then, register routes to this controllers in Startup Configure section.

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

This is pretty straightforward and basic configuration for controllers, you can change this configuration as you need. Official docs are available here.

In your Views folder

Create a cshtml template under any views folder e.g.

Views/Emails/Registration.cshtml

This template will be associated to a model so we can change values dynamically.

The content of cshtml can be

@model UserRegistrationInfo
Hello <strong>@Model.UserName</strong> your email is <strong>@Model.Email</strong>

NOTE: For emails you have to use inline styling. This means that all CSS values must be inlined in your view file (or any HTML of some sort). For this task you can use Foundation for Emails or any web-based editor.

Usage in Controllers

Emails must be send inside a controller action, plain old MVC. Our mailer service is properly registered in our Startup.cs so we can use built-in DI in any controller constructor like this:

Constructor

private readonly ICoreMvcMailer _mailer;

public HomeController(ICoreMvcMailer mailer)
{
  _mailer = mailer;
}

In ActionMethod Now you can send emails inside any action, in this example we use the SencAsync method:

[AllowAnonymous]
[HttpGet("users/notify")]
public async Task<IActionResult> NotifyUser(string username, string email)
{
    UserRegistrationInfo newUser = new UserRegistrationInfo()
    {
        UserName = username,
        Email = email 
    };

    MailerModel notifier = new MailerModel("YourHostName",1234)
    {
        FromAddress = "Your Address",
        IsHtml = true,
        User = "YourUserName",
        Key ="YourKey",
        ViewFile = "Emails/Register",
        Subject = "Registration",
        Model = newUser
    };
        
    await _mailer.SendAsync(notifier);
    return View();
}

       

UPDATE 2018-01-04

Added support to use local folder instead of using paid or free mail servers.

HOW TO USE ?

It is really simple to use. Just create MVCMailer model with pickup directory location. When you send the email make sure you set sender and reciver email. Once done, you can see email in your provided pickup directory.

        MailerModel notifier = new MailerModel(**"Your Directory Here"**)
        {
            FromAddress = "Your Address",
            IsHtml = true,
            User = "YourUserName",
            Key ="YourKey",
            ViewFile = "Emails/Register",
            Subject = "Registration",
            Model = newUser
        };
        notifier.ToAddresses.Add("test@test.com");
        _mailer.Send(mdl);

LICENSE

CORE MAILER

Copyright (C) Since 2017, Riy Technologies AB.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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
1.0.2 1,409 4/17/2020
1.0.0 596 1/23/2020

Based on Riyasat CoreMailer, this project send emails from within ASPNET.Core 3.1 or above with razor templates.