38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Text.Json;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Program
|
|
{
|
|
static async Task Main()
|
|
{
|
|
string jsonFilePath = "appsettings.json";
|
|
string jsonString = File.ReadAllText(jsonFilePath);
|
|
|
|
var options = new JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
SmtpSettings? smtpSettings = JsonSerializer.Deserialize<SmtpSettings>(jsonString, options);
|
|
|
|
if (smtpSettings is null)
|
|
{
|
|
Console.WriteLine("Failed to deserialize SmtpSettings");
|
|
return;
|
|
}
|
|
|
|
MailService mailService = new MailService(smtpSettings);
|
|
await mailService.SendEmailText("user@user.com", "Hello World", "Hello World from C#!");
|
|
|
|
Dictionary<string, string> replacements = new Dictionary<string, string>
|
|
{
|
|
{ "name", "Jonas" }
|
|
};
|
|
|
|
await mailService.SendEmailHtmlFile("user@user.com" , "Hello World", "email.html", replacements);
|
|
|
|
|
|
}
|
|
}
|
|
} |