mailkit - 将smtp4dev用作Mailkit客户端消息的服务器的推荐方法

标签 mailkit smtp4dev

我有一个控制台应用程序,并且安装了mailkit软件包以用于消息传递目的。

我在测试mailkit smtp客户端的主要方法中有代码。我正在运行smtp4dev虚拟服务器,并且客户端代码是带有注释身份验证部分的example code of mailkit in github,主机是localhost和端口26,与smtp4dev配置匹配。

当执行客户端代码时,smtp4dev stop running和未处理的异常发生IOException: Unable to read data from the transport connection: an existing connection was forcibly closed by the remote host.
如何配置smtp4dev从mailkit客户端接收消息?

最佳答案

经过一番尝试和错误,我在以下安排上取得了成功。
smtp4dev options

我的代码类似于https://github.com/jstedfast/MailKit#sending-messages:

public void DoMail()
{
    var message = new MimeMessage();
    message.From.Add(new MailboxAddress("Joey", "joey@friends.com"));
    message.To.Add(new MailboxAddress("Alice", "alice@wonderland.com"));
    message.Subject = "How you doin?";

    message.Body = new TextPart("plain")
    {
        Text = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
"
    };

    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("localhost", 25, 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("joey", "password");

        client.Send(message);
        client.Disconnect(true);
    }
}

对于无法访问imgur的用户:
域名:localhost
监听界面:0.0.0.0
端口号:25(不过,在Dalsier的情况下,Dalsier会使用26)
扩充功能:
  • []隐式SSL/TLS
  • [x] 8BITMIME
  • [] STARTTLS
  • [] AUTH
  • [x]大小

  • SSL/TLS证书:无
    SSL/TLS证书密码:无
    最大邮件大小(字节):0
    接收超时(毫秒):30000
    选项:
  • []需要认证
  • []需要安全连接
  • []仅允许通过安全连接进行明文身份验证
  • 关于mailkit - 将smtp4dev用作Mailkit客户端消息的服务器的推荐方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34637644/

    相关文章:

    c# - 使用 MailKit,带有 unicode 文件名的附件在 Outlook 中显示为 "untitled attachment"

    c# - 当没有文件夹命名空间时,在 MailKit 中打开邮件文件夹

    centos - MailKit 使用 LetsEncrypt SSL 证书获取 SslHandshakeException

    .net - 如何创建防止 "server mode SSL must use certificate with associated private key"异常的 X509 证书?

    c# - 如何使用 smtp4dev 接收电子邮件

    .net - 在 ASP NET MVC 6 项目中使用 System.Net.Mail

    c# - Mailkit:获取消息并将它们复制到 MySQL,附件到驱动器