Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mailkit authenticating self hosted email with my exchange server?

Essentially, I have a local mail server with exchange and active directory and etc.. I'm trying to authenticate an email with Mailkit in C# but I get an authentication error every single time. I've tried many different ways of using client#Authenticate by using "int\name", "password" or "name", "password" or "address", "password" etc. Here's my code:

public Email()
    {

        var message = new MimeMessage();
        message.From.Add(new MailboxAddress("", "[email protected]"));
        message.To.Add(new MailboxAddress("", "[email protected]"));
        message.Subject = "test email";

        message.Body = new TextPart("plain")
        {
            Text = @"test"
        };

        var client = new SmtpClient();
        client.Connect("my.mailserver.com", 25, MailKit.Security.SecureSocketOptions.StartTls);
        client.Authenticate("[email protected]", "mypassword");
        client.Send(message);

        client.Disconnect(true);
    }

enter image description here

like image 928
sethsource Avatar asked Sep 18 '25 19:09

sethsource


1 Answers

Fixed it everyone. Hopefully someone can benefit from this in the future.

Fixed it by using port 587 instead of 25, and also by using fqdn\username

like image 150
sethsource Avatar answered Sep 20 '25 08:09

sethsource