Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: chaine de connexion sql server c# 
Csharp :: C# Func Delegate 
Csharp :: www.elking.net 
Csharp :: lamda expression multiple and 
Csharp :: Initalize C# project in VS Code 
Csharp :: Accepts one of 1, 2, x or X, or nothing 
Csharp :: single number c# 
Csharp :: C# JOSN Array Conversion 
Csharp :: c# picturebox zoom 
Csharp :: c# generic type converter 
Csharp :: create cursor in netezza 
Csharp :: unity int inputfield value 
Csharp :: encode < for xml 
Csharp :: como ordenar dados na gridview c# 
Csharp :: button pervious for picturebox c# 
Csharp :: Set database timeout in Entity Framework 
Csharp :: split nullable in c# 
Csharp :: how to run a console app in another app c# 
Csharp :: how to reset checkbox visual studio c# 
Csharp :: datagridview show noti each row column 
Csharp :: compass direction mobile unity 
Csharp :: Post and Pre Increment operators in C# 
Csharp :: how to create more accurate searching c# 
Csharp :: get patht bim 360 revit api 
Csharp :: c# how to start an application and detect if started 
Csharp :: .net entities query multiple join condition 
Csharp :: how to declare two int variables in only one line c# 
Csharp :: how to coppy a portion of an array in c# 
Csharp :: Area Of the triangle with condition 
Csharp :: index in foreach in c# 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =