1

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);
}
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
Alexe Barlescu
  • 387
  • 4
  • 11
  • There are lots of examples online for sending emails from C#. Search for your specific error too, that will help. – Luke Feb 07 '17 at 11:54
  • 3
    Possible duplicate of [Send e-mail via SMTP using C#](http://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp) – Luke Feb 07 '17 at 11:55

0 Answers0