MailKit使用我的Exchange Server身份验证自托管的电子邮件?

发布于 2025-01-26 09:59:54 字数 1322 浏览 2 评论 0原文

从本质上讲,我有一个带有Exchange和Active Directory等的本地邮件服务器。我试图在C#中使用MailKit进行身份验证电子邮件,但每次都会遇到身份验证错误。我尝试使用“ int \ name”,“ password”或“ name”,“ password”或“地址”,“密码”等多种不同的方法来使用client#Authentication

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

。 https://i.sstatic.net/lpt6g.png“ rel =“ nofollow noreferrer”>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你鎻心 2025-02-02 09:59:54

修复了每个人。希望将来有人可以从中受益。

通过使用端口587而不是25,还使用FQDN \用户名来修复它

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文