标签: mailkit

MailKit:从IMAP服务器获取新邮件通知

我需要创建一个连接到IMAP服务器并侦听新邮件的服务(或控制台)应用程序.我目前正在尝试使用MailKit,但我无法从文档中找出如何实现这一目标.

我最接近的是这篇文章.从我所看到的,这篇文章是将连接设置为IDLE模式,偶尔发送NoOP以尝试保持连接活动.我不完全清楚的是如何收到新的邮件通知.

MailKit文档似乎表明有一个Alert事件可用.我试过挂钩,但这似乎没有解决任何问题.

这是我尝试过的:

    var cts = new CancellationTokenSource();
    testIDLEMailNotification(cts.Token);

    ...

    private static void testIDLEMailNotification(CancellationToken token)
    {
        using (var client = ClientCreateAndConnect(token))
        {
            while(!token.IsCancellationRequested)
            {
                using (var done = new CancellationTokenSource())
                {
                    using (var timer = new System.Timers.Timer(9 * 60 * 1000))
                    {
                        timer.Elapsed += (sender, e) => done.Cancel();
                        timer.AutoReset = false;
                        timer.Enabled = true;
                        try
                        {
                            client.Idle(done.Token, token);
                            client.NoOp(token);

                        }
                        catch (OperationCanceledException)
                        {
                            break;
                        }
                    }
                }
            }
        }
    }

    private static ImapClient ClientCreateAndConnect(CancellationToken token)
    {
        var …
Run Code Online (Sandbox Code Playgroud)

c# imap mailkit

5
推荐指数
2
解决办法
5915
查看次数

如何修改消息体 - Mimekit消息

我正在使用mimekit接收和发送我的项目的邮件.我发送收到的邮件进行了一些修改(来自和来自部分).现在我需要修改身体部分.我将用asterix字符替换特定的单词.每封邮件的具体文字不同.邮件可以是任何格式.你可以看到我找到了我想要的但我不知道如何更换没有任何错误?

在此输入图像描述

c# email message mailkit mimekit

5
推荐指数
1
解决办法
1588
查看次数

Mailkit 无法使用 O365 oAuth2 帐户进行身份验证

我尝试对在 Azure 门户上创建的 O365 应用程序进行身份验证,但它无法按预期工作。

以下代码运行良好,但它使用登录名/密码,并且 Microsoft 不推荐。(在这里找到https://github.com/jstedfast/MailKit/issues/989

var scopes = new[] { "https://outlook.office365.com/IMAP.AccessAsUser.All" };

var confidentialClientApplication = PublicClientApplicationBuilder.Create(_clientId).WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs).Build();

SecureString securePassword = new NetworkCredential("", _userPassword).SecurePassword;
var acquireTokenByUsernamePasswordParameterBuilder = confidentialClientApplication.AcquireTokenByUsernamePassword(scopes, _userMail, securePassword);
var authenticationResult = acquireTokenByUsernamePasswordParameterBuilder.ExecuteAsync().Result;

if (_debugCall)
{
imapClient = new ImapClient(new ProtocolLogger(_configurationId + "_IMAP_" + DateTime.Now.ToString("yyyyMMddHHssffff") + ".log"));
}
else
{
imapClient = new ImapClient();
}
        
imapClient.CheckCertificateRevocation = false;
imapClient.ServerCertificateValidationCallback = (s, c, h, e) => true;

imapClient.Connect(_webServiceUrl, _webServicePort, SecureSocketOptions.Auto);
imapClient.Authenticate(new SaslMechanismOAuth2(_userMail, authenticationResult.AccessToken));  

if (string.IsNullOrEmpty(_folder))
{
oFolder …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 office365 mailkit

5
推荐指数
1
解决办法
3348
查看次数

c#MailKit - 阅读收据

有人知道MailKit是否支持读取收据(读取时回复消息)?我没有在网上或Stackoverflow上找到任何东西.

c# mailkit

4
推荐指数
1
解决办法
1116
查看次数

Mimekit/mailkit下载邮件正文?

我最近一直在制作自己的邮件客户端,并添加了一个接收选项,我使用mimekit和mailkit作为插件,并且能够使用应该显示内容的阅读器下载我的大部分邮件(现在它显示主题,来自,来自, ,日期)

我下载主题的方式是,...是msg.envelope.subject,msg.envelope.to但我无法下载这样的主体:(当做msg.body,msg.textbody,msg.bodyparts ,. ..他们都导致了NOTHING,它应该是空的地方,我无法下载:(

谁能帮我?

c# mailkit mimekit

4
推荐指数
1
解决办法
4351
查看次数

使用Mailkit丢失附件

当我使用MailKit通过IMAP协议收到来自Exchange的邮件时,它缺少附件.当我做:

string.Format("Mail has {0} attachments", mime.Attachments.Count())
Run Code Online (Sandbox Code Playgroud)

它报告"0",即使邮件本身包含附件(如果我在Outlook客户端中打开它,我会看到附件)​​,当我激活IMAP协议日志记录时,显然它包含一个附件:

S: X-MS-Has-Attach: yes
...
S: Content-Type: message/rfc822
S: Content-Disposition: attachment;
S:  creation-date="Thu, 07 Jan 2016 09:16:53 GMT";
S:  modification-date="Thu, 07 Jan 2016 09:16:53 GMT"
...
S: X-MS-Has-Attach:
...
Run Code Online (Sandbox Code Playgroud)

有趣的是附件部分中的"S:X-MS-Has-Attach:"标题,位于服务器的同一个包中.

这是一个已知的问题,我该如何修复它以便在这些情况下我不会错过附件?它似乎只发生在一些邮件上并随机发生.

使用:MailKit 1.0.14.0 MimeKit 1.0.13.0

我发现有新的更新,但如果不能解决问题,我不会真正更新.

c# mailkit mimekit

4
推荐指数
1
解决办法
932
查看次数

DKIM 签名失败,正文哈希未验证 Mimekit 1.10.1.0 和 Mailkit 1.10.2.0

当 DKIM 使用 Mailkit 和 Mimekit 签署标头时,我看到一个奇怪的问题,Gmail 报告错误“dkim=neutral(正文哈希未验证)”。

我在这里做错了吗?请在下面找到我的代码和屏幕截图Gmail 图片 1 标题附上实际收到的邮件。

        string ReturnName = "DMC12";
        string FromDomain = "backtothefuture.net";
        string FromEmail = "marty@" + FromDomain;
        string FromName = "Marty McFly";
        string SenderName = "Marty McFly";
        string ToEmail = "George.mcfly.1960@gmail.com";
        string MailServer = "DMC12.large.timemachine.com";
        string TextBody = @"If you put your mind to it, you can accomplish anything. One other thing. If you guys ever have kids, and one of them, when he's eight years old, accidentally sets fire to the living …
Run Code Online (Sandbox Code Playgroud)

c# dkim mailkit mimekit

4
推荐指数
1
解决办法
1067
查看次数

AuthenticationException:AuthenticationMechanismTooWeak:5.7.14

我在Web应用程序上使用MVC ASP.NET Core 1.1.2.我尝试使用MailKit 1.18.1.1创建联系表单.我通过电子邮件(gmail)发送联系表格信息.当我在本地构建网页时,一切都按预期工作.我第一次在本地运行程序,它给了我同样的错误,但我启用了我的邮件地址的安全设置,它开始工作.但是当我在网络上部署它时,即使我设置安全设置以启用安全性较低的应用程序,它也会给我一个这样的错误:

AuthenticationException错误页面

这是Home Controller中的SendMail方法:

public IActionResult SendMail(string name, string phone, string email, string msg)
        {
            var message = new MimeMessage();
            message.From.Add(new MailboxAddress ("theemailaddress@gmail.com"));
            message.To.Add(new MailboxAddress("theemailaddresswhichrecievestheinfo@gmail.com"));
            message.Subject = name;
            message.Body = new TextPart("html")
            {
                Text = "Kimden: " + name + "<br>" + "Mail adresi: " + email + "<br>" +
                "Mesaj: " + msg + "<br>" + "Telefon: " + phone
            };

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587);
                client.Authenticate("theemailaddress@gmail.com", "thepassword(I am sure it's correct)"); …
Run Code Online (Sandbox Code Playgroud)

html c# asp.net-mvc mailkit asp.net-core

4
推荐指数
1
解决办法
1833
查看次数

尝试连接到“ smtp.office365.com”时出现MailKit.Security.SslHandshakeException

我正在尝试使用MailKit通过“ smtp.office365.com”发送电子邮件。这是我正在使用的代码。

using (var client = new SmtpClient(new ProtocolLogger("smtp.log")))
{
    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
    client.Connect("smtp.office365.com", 587, SecureSocketOptions.SslOnConnect);
    client.Authenticate(new SaslMechanismNtlmIntegrated());
    Debug.WriteLine(client.IsAuthenticated);
    client.Send(message);
    client.Disconnect(true);
}
Run Code Online (Sandbox Code Playgroud)

SaslMechanismNtlmIntegrated我从GitHub上的此评论获得的课程。

每当我运行此代码时,我都会得到一个SslHandshakeException

以下是例外的详细信息:

MailKit.Security.SslHandshakeException
  HResult=0x80131500
  Message=An error occurred while attempting to establish an SSL or TLS connection.

One possibility is that you are trying to connect to a port which does not support SSL/TLS.

The other possibility is that the SSL certificate presented by the server is not …
Run Code Online (Sandbox Code Playgroud)

c# email ssl mailkit

4
推荐指数
1
解决办法
2220
查看次数

Mailkit does not authenticate with credentials

I'm trying to send an email with Gmail account. I was able to send emails with yahoo, however, it doesn't work anymore, for some unknown reason. Which i posted a question about that as well, but not response.

In this instance, i'm trying to connect to a gmail account so that I can send emails, but with no luck, it fails after the Connect.

It connects successfully but doesn't authenticate at all, although I have the right credentials.

This is …

email smtp smtpclient smtp-auth mailkit

4
推荐指数
2
解决办法
2890
查看次数