Files
WhiteLagoon/WhiteLagoon.Infrastructure/Emails/EmailService.cs
T
2025-05-20 11:46:50 -04:00

39 lines
1.2 KiB
C#

using Microsoft.Extensions.Configuration;
using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using WhiteLagoon.Application.Contract;
namespace WhiteLagoon.Infrastructure.Emails
{
public class EmailService : IEmailService
{
private readonly string _sendGridKey;
public EmailService(IConfiguration configuration)
{
_sendGridKey = configuration["SendGrid:Key"];
}
public async Task<bool> SendEmailAsync(string email, string subject, string message)
{
var client = new SendGridClient(_sendGridKey);
var from = new EmailAddress("hello@dotnetmastery.com", "DotNetMastery - White Lagoon");
var to = new EmailAddress(email);
var msg = MailHelper.CreateSingleEmail(from, to, subject, "", message);
var response = await client.SendEmailAsync(msg);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted || response.StatusCode == System.Net.HttpStatusCode.OK)
{
return true;
}
return false;
}
}
}