An open API service indexing awesome lists of open source software.

https://github.com/EdiWang/Edi.TemplateEmail

Configure content template in xml and send email
https://github.com/EdiWang/Edi.TemplateEmail

Last synced: about 1 year ago
JSON representation

Configure content template in xml and send email

Awesome Lists containing this project

README

          

Edi.TemplateEmail
===============================

This library enable you to configure email in XML template and send the email in your .NET applications.

> Currently, only SMTP Basic Authentication is supported.

[![NuGet][main-nuget-badge]][main-nuget]

[main-nuget]: https://www.nuget.org/packages/Edi.TemplateEmail/
[main-nuget-badge]: https://img.shields.io/nuget/v/Edi.TemplateEmail.svg?style=flat-square&label=nuget

## Install

```
dotnet add package Edi.TemplateEmail
```

## Usage

### Step 1: Put a mailConfiguration.xml somewhere you like

```xml



Test Mail on {MachineName.Value}


Smtp Server: {SmtpServer.Value}

Smtp Port: {SmtpServerPort.Value}

Smtp Username: {SmtpUserName.Value}

Email Display Name: {EmailDisplayName.Value}

Enable SSL: {EnableSsl.Value}

]]>

```

### Step 2:

Initialize the `EmailHelper` by your mail server settings

```
// Change these values
var smtpServer = "smtp.example.com";
var userName = "test1@example.com";
var password = "********";
var port = 25;
var toAddress = "test2@test.com";

var configSource = $"{Directory.GetCurrentDirectory()}\\mailConfiguration.xml";
var emailHelper = new EmailHelper(configSource, new(smtpServer, userName, password, port)
{
SenderName = senderName,
EmailDisplayName = displayName
});
```

### Step 3: Map the values and send Email

```
var message = emailHelper.ForType("TestMail")
.Map("MachineName", Environment.MachineName)
.Map("SmtpServer", emailHelper.Settings.SmtpServer)
.Map("SmtpServerPort", emailHelper.Settings.SmtpServerPort)
.Map("SmtpUserName", emailHelper.Settings.SmtpUserName)
.Map("EmailDisplayName", emailHelper.Settings.EmailDisplayName)
.Map("EnableTls", emailHelper.Settings.EnableTls)
.BuildMessage([toAddress]);

var result = await message.SendAsync();
```