32 lines
868 B
C#
32 lines
868 B
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
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);
|
|
mailService.SendEmail("user@user.com", "Hello World", "Hello World from C#!");
|
|
|
|
}
|
|
}
|
|
} |