Mimekit等待客户端。authenticateasync(用户名,密码)不使用字符串vars

发布于 2025-02-01 08:00:56 字数 1189 浏览 3 评论 0原文

这让我感到震惊!我需要通过DB的电子邮件发送SMTP电子邮件(以后可以更改电子邮件和PWD)。问题是...仅当我在引号中设置用户名和密码时才连接。 我正在使用Mimekit 3.2,.net6.0;

 using var client = new MailKit.Net.Smtp.SmtpClient {                   
                CheckCertificateRevocation = false,
                ServerCertificateValidationCallback = (s, c, h, e) => true,
            };
            
                ...
                try
                {

                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    await client.ConnectAsync(_smtpDetails.Server, _smtpDetails.Port, SecureSocketOptions.SslOnConnect, default);

                    await client.AuthenticateAsync("[email protected]", "mypwd"); This works but i need to authenticate using  await client.AuthenticateAsync(string.Username, string.Pwd)!!

                    await client.SendAsync(mimeMessage);
                }
                finally
                {
                    await client.DisconnectAsync(true);
                }
             }

...

我试图创建凭据,班级等,但没有成功!

谢谢。

It's driving me crazzy!! I need to send smtp emails with an email from db (which i can later alter the email and the pwd as well). The thing is...it only connects if i set username and password inside quotes.
I'm using mimekit 3.2, .net6.0;

 using var client = new MailKit.Net.Smtp.SmtpClient {                   
                CheckCertificateRevocation = false,
                ServerCertificateValidationCallback = (s, c, h, e) => true,
            };
            
                ...
                try
                {

                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    await client.ConnectAsync(_smtpDetails.Server, _smtpDetails.Port, SecureSocketOptions.SslOnConnect, default);

                    await client.AuthenticateAsync("[email protected]", "mypwd"); This works but i need to authenticate using  await client.AuthenticateAsync(string.Username, string.Pwd)!!

                    await client.SendAsync(mimeMessage);
                }
                finally
                {
                    await client.DisconnectAsync(true);
                }
             }

...

I've tried to create credentials, a class, etc, but no success!

Thanks.

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

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

发布评论

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

评论(1

镜花水月 2025-02-08 08:00:56

如果您发现使用硬编码(引用)字符串有效但使用字符串变量的问题始终是您的字符串变量不包含您认为它们包含的值。

打印出(或使用调试器)来验证它们是否完全包含应包含的内容。

一个非常常见的问题是,字符串变量在字符串值的开头或结尾(或newline序列)中包含空格。

If you find that you are having a problem where using hard-coded (quoted) strings works but using a string variable doesn't, the problem is ALWAYS that your string variables don't contain the value(s) that you think they contain.

Print out (or use the debugger) to verify that they contain EXACTLY what they are supposed to contain.

A very common problem is that the string variable contains whitespace at the beginning or end of the string value (or a newline sequence).

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