标签: mailkit

MailKit:搜索自定义标头是否存在

我有条件地在电子邮件中添加了自定义标头

我想使用 IMAP/SearchQuery 仅返回具有标题的邮件。

不是它的值,仅在标头存在时返回 true/false。

是否可以 ?谢谢。

mailkit

2
推荐指数
1
解决办法
1216
查看次数

使用 Mailkit 获取收件箱更改通知

使用 MailKit 在我的邮箱的收件箱中发生邮件或更改时,获得即时通知的最佳方式是什么?

我一直在玩以下事件: ImapClient.Inbox.CountChanged; 这在使用 Exchange 服务器时似乎效果最好,因为它们根本不会对 MessageArrived 事件做出反应。噗..

ImapClient.Inbox.MessagesArrived; 这似乎在 SquirrelMail 等开源邮件服务器上运行良好,但在 Exchange 中根本不起作用。

我想在新邮件到达邮箱时收到通知,是否有任何邮件被移动/删除,以及是否有任何邮件移动到此 imap 文件夹。当我的收件箱发生问题时,我应该采取哪种方法来尽快收到事件?我想要两全其美。

什么是 ImapClient.Inbox.Subscribe(); 用于??

c# mailkit

2
推荐指数
1
解决办法
3340
查看次数

使用 993 端口和 MailKit “IMAP 服务器意外断开连接”

我最近将代码移至 MailKit 库,因为我使用的是 S22.Imap,但我发现维护不是很好。

我之前通过143和993连接自己的邮件服务器,但是通过993和MailKit没有办法。

它只是说“IMAP 服务器意外断开连接”。它甚至没有到达 Authenticate 方法,并且日志中唯一显示“已连接到 imap://mail.xxx.com:993/”。

我目前正在使用

imap.Connect(hostname, 993, SecureSocketOptions.None);
Run Code Online (Sandbox Code Playgroud)

我什至尝试过使用不同的 SecureSocketOptions,但没有成功。知道可能出什么问题吗?如果我通过 143 连接则工作正常,而当我使用 S22.Imap 时则通过 993 连接则工作正常。

PS:它抛出的异常是MailKit.Net.Imap.ImapProtocolException.

谢谢。

.net c# imap mailkit

2
推荐指数
1
解决办法
9443
查看次数

如何从 IMessageSummary 获取 MimeMessage?

我正在使用 MailKit 获取完整的 IMessageSummaries 列表,如下所示:

var allMessages = remoteFolder.Fetch(remoteIndexList, MessageSummaryItems.Full | MessageSummaryItems.Flags | MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);
Run Code Online (Sandbox Code Playgroud)

我对任何优化不感兴趣,例如下载 IMessageSummary 的部分内容等,我只想要整个数据,尽快获取。

但是使用上述方法,我无法正确读取消息正文中的 HTML,例如使用,HtmlPreviewVisitor因为Body的属性IMessageSummaryBodyPartBasic. 显然,我需要整个MimeMessage

问题是,如果我想获得多个MimeMessages,我不能,我只能使用方法一次获得一个ImapClient.GetMessage(int index, ...)

MimeMessage有没有一种方法可以从用于创建IMessageSummary和使用它们的原始文件中提取所有部分,而HtmlPreviewVisitor无需再次下载完整的部分MimeMessage

mailkit

2
推荐指数
1
解决办法
1601
查看次数

MailKit 设置 MessageFlag 在 Append 后看到

我使用 MailKit.Net.Smtp.SmtpClient 发送 MailKit.Message Async。

然后我把邮件放在发送文件夹中,但邮件标志是看不见的。

我无法在 Message 构建中设置 messageflag,只能在 Append 之后,但我发现无法转换MailKit.UniqueId?MailKit.UniqueId

 var folderSend = IC.GetFolder(MailKit.SpecialFolder.Sent);
 MailKit.UniqueId? te = folderSend.Append(nochmalMessage);
 folderSend.AddFlagsAsync(te, MailKit.MessageFlags.Seen, true);
Run Code Online (Sandbox Code Playgroud)

te必须是 MailKit.UniqueId

c# imap unique-id mime-message mailkit

2
推荐指数
1
解决办法
718
查看次数

MAILKIT 如何将邮件移动到文件夹并获取新的 UniqueID

MailKit.Net.Imap 有 MoveTo(...)。但是,如果我们移动消息,消息将获得新的 UniqueID(因为它在文件夹中是唯一的)。如何获取消息的新 UniqueID?

c# mailkit mimekit

2
推荐指数
1
解决办法
2108
查看次数

使用 Mailkit 连接时何时应该使用 SecureSockOptions 或 useSsl

我对在使用 MailKit 设置 smtp 时如何使用第三个参数感到困惑。

这是我到目前为止所拥有的:

    // *************** SEND EMAIL *******************
    using (var client = new MailKit.Net.Smtp.SmtpClient(new ProtocolLogger("smtp.log")))
    {
      client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;

      //accept all SSL certificates
      client.ServerCertificateValidationCallback = (s, c, h, e) => true;

      // Note: since we don't have an OAuth2 token, disable
      // the XOAUTH2 authentication mechanism.
      client.AuthenticationMechanisms.Remove("XOAUTH2");

      // client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort, emailSettings.IsSslEnabled);
      client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort, emailSettings.AuthType);

      if (emailSettings.IsAuthenticationRequired)
      {
        // Note: only needed if the SMTP server requires authentication
        client.Authenticate(emailSettings.SmtpUsername, emailSettings.SmtpPassword);
      }

      if (emailSettings.TimeOut == 0) emailSettings.TimeOut = 10; …
Run Code Online (Sandbox Code Playgroud)

c# smtp winforms mailkit

2
推荐指数
1
解决办法
5199
查看次数

使用 Mailkit:“SMTP 服务器意外断开连接。”

我正在尝试使用 SendGrid 的免费 SMTP 中继从我的 ASP.NET 应用程序发送电子邮件。我可以连接到服务器,但当我尝试进行身份验证时,收到此错误:“SMTP 服务器意外断开连接。”

using (var client = new SmtpClient())
        {
            client.ServerCertificateValidationCallback =
                (sender, certificate, certChainType, errors) => true;
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // connection
            client.Connect("smtp.host", 465, true);
            client.Authenticate("UserName", "Password");//error occurs here

            client.Send(email);
            client.Disconnect(true);
        }
Run Code Online (Sandbox Code Playgroud)

再次,我可以毫无问题地连接,但是当我尝试进行身份验证时,我收到前面提到的错误......

有什么建议么?

干杯

c# smtp smtpclient smtp-auth mailkit

2
推荐指数
1
解决办法
2万
查看次数

MailKit IMAP Idle - 如何在 CountChanged 事件中访问“完成”CancellationTokenSource

我正在使用此处找到的 IMAP Idle 示例代码

该示例需要 Console.ReadKey 来取消 CancellationTokenSource,但建议只要该事件有权访问 CancellationTokenSource,就可以在新邮件到达时在 CountChanged 事件中取消它。

如何访问 CountChanged 事件中的 CancellationTokenSource?

这是上面链接中的代码片段......

// Keep track of changes to the number of messages in the folder (this is how we'll tell if new messages have arrived).
client.Inbox.CountChanged += (sender, e) => {
    // Note: the CountChanged event will fire when new messages arrive in the folder and/or when messages are expunged.
    var folder = (ImapFolder)sender;

Console.WriteLine("The number of messages in {0} has changed.", folder);

    // Note: …
Run Code Online (Sandbox Code Playgroud)

c# imap mailkit

2
推荐指数
1
解决办法
1937
查看次数

Mailkit 支持发送匿名电子邮件吗?

我尝试发送电子邮件的 Exchange 主机不需要身份验证。过去我已经使用 SmtpClient 类成功实现了这一目标,但由于 Microsoft 推荐 Mailkit,我更喜欢使用这个。

Mailkit 是否始终需要用户名和密码才能连接?我一直在到处寻找答案,但似乎找不到。

到目前为止,这是我的代码:

        private void Send(MimeMessage message)
        {
            using (var client = new SmtpClient(new ProtocolLogger(Console.OpenStandardOutput())))
            {
            client.Connect(Host, Port, SecureSocketOptions.None);             

            client.Send(message);
            client.Disconnect(true);
            }
        }
Run Code Online (Sandbox Code Playgroud)

当然,我收到错误:5.7.1 客户端未经过身份验证

谢谢你。

c# exchange-server mailkit

2
推荐指数
1
解决办法
4006
查看次数