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
- Host: GitHub
- URL: https://github.com/EdiWang/Edi.TemplateEmail
- Owner: EdiWang
- License: mit
- Created: 2014-02-28T04:30:42.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T04:22:39.000Z (over 2 years ago)
- Last Synced: 2024-03-04T05:30:24.284Z (over 2 years ago)
- Language: C#
- Homepage:
- Size: 581 KB
- Stars: 11
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
```