Mimekit等待客户端。authenticateasync(用户名,密码)不使用字符串vars
这让我感到震惊!我需要通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发现使用硬编码(引用)字符串有效但使用字符串变量的问题始终是您的字符串变量不包含您认为它们包含的值。
打印出(或使用调试器)来验证它们是否完全包含应包含的内容。
一个非常常见的问题是,字符串变量在字符串值的开头或结尾(或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).