What is the easiest way to have form data sent to an email address , in an asp.net core app? I have tried to send an email from my outlook account to gmail one wit Mailkit, but i keep getting an error AuthenticationException: AuthenticationInvalidCredentials , even if my credentials are corect.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "joey@outlook.com"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "Chandler@gmail.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain")
{
Text = @"Hey Chandler"
};
using (var client = new SmtpClient())
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.outlook.com", 587, false);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("username", "*************");
client.Send(message);
client.Disconnect(true);
}