Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Enviar correos en C# con MailKit

[HttpPost]
public ActionResult<IEnumerable<bool>> 
SendEmail([FromBody] string emailData)
{
    try
    {
        var message = new MimeMessage();
        message.From.Add(new MailboxAddress("TheCodeBuzz", "xxxx@gmail.com"));
        message.To.Add(new MailboxAddress("TheCodeBuzz", "infoATthecodebuzz.com"));
        message.Subject = "My First Email";
        message.Body = new TextPart("plain")
        {
            Text = emailData
        };
        
            using (var client = new MailKit.Net.Smtp.SmtpClient())
            {
 
                client.Connect("smtp.gmail.com", 587, false);
 
                //SMTP server authentication if needed
                client.Authenticate("xxxx@gmail.com", "xxxxx");
 
                client.Send(message);
 
                client.Disconnect(true);
            }
 
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        return StatusCode(500, "Error occured");
    }
 
    return Ok(true);
}
Source by www.thecodebuzz.com #
 
PREVIOUS NEXT
Tagged: #Enviar #correos #en #MailKit
ADD COMMENT
Topic
Name
1+3 =