Skip to content

Latest commit

 

History

History
89 lines (80 loc) · 1.98 KB

README.md

File metadata and controls

89 lines (80 loc) · 1.98 KB

Configuration

appsettings.json

"EmailServiceOptions": {
  "ApiEmail": "<email_name>@<domain_name>",
  "ApiToken": "<your_domain_token>",
  "ApiUrl": "https://api.mailersend.com/v1/email"
}

Program.cs

//----- Libraries injection
builder.Services.AddScoped<MailerSendService>();

Controller

using MailerSendApi;
using MailerSendApi.Models;
using Microsoft.AspNetCore.Mvc;

namespace SchoolApi.Controllers
{
  [Route("api/emails")]
  [ApiController]
  public class MailerSendController: ControllerBase
  {
    // Dependency injection of mailerSendService
    private readonly MailerSendService _mailerSendService;
    public MailerSendController(MailerSendService mailerSendService)
    {
      _mailerSendService = mailerSendService;
    }

    [HttpGet]
    public async Task<string> GetAll()
    {
      Email newEmail = new Email
      {
        To = 
        [
          new Recipent{Email = "<recipent_email>"}
        ],
        Subject = "Email from backend",
        Html = "This is an email generate from backend, but with Library"
      };

      string emailInfo = await _mailerSendService.SendEmail(newEmail);
      return emailInfo;
    }
  }
}