azure email sender

 using Microsoft.AspNetCore.Http;

using Microsoft.AspNetCore.Mvc;

using System;

using System.Collections.Generic;

using Azure.Communication.Email;

using Azure;

//using Azure.Communication.Email.Models;

namespace NMBEmailer.Controllers

{

    [ApiController]

    [Route("[controller]")]

    public class EmailController : Controller

    {

        [HttpGet(Name = "SendEmail")]

        public async Task<ActionResult<string>> GetUserInfo(string email, string name)

        {

            // This code retrieves your connection string from an environment variable.

            string connectionString = "endpoint=https://com-service-nmb.asiapacific.communication.azure.com/;accesskey=6eIgegVgnogMKha3Elylm+17NYqIFSwJb+chnd0I780r85B510/3t4wqPM96pmtEZY5JxRLk4Hu/cEN/j0verg==";

            var emailClient = new EmailClient(connectionString);


            EmailSendOperation emailSendOperation = await emailClient.Send(

            WaitUntil.Completed,

                from: "tran-alert@nmb.com.np",

                to: "<to_email>",

                subject: "Test Email",

                htmlContent: "<html><h1>Hello world via email.</h1></html>",

                plainTextContent: "Hello world via email."

            );


            return Ok("Success");

        }


    }

}


solution is here

https://jayanttripathy.com/how-to-send-emails-from-asp-net-core-using-azure/


Comments