gpt4 book ai didi

c# - smtpclient 不适用于 Exchange 服务器,但适用于 smtp 服务器

转载 作者:行者123 更新时间:2023-12-04 18:21:43 28 4
gpt4 key购买 nike

我写了一个非常基本的类来发送电子邮件。我用 smtp 服务器对其进行了测试,它工作正常,但是当我尝试使用我公司的交换服务器时,它给出了这个异常:

SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.1 客户端未通过身份验证

我的代码如下:

MailMessage mailMessage = new MailMessage("From@company.com", "To@company.com", "Test Subject", "Void body");
SmtpClient smtpClient = new SmtpClient(smtpServerAddress, smtpServerPort);
NetworkCredential credentials = new NetworkCredential(AccountName,Password);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; // without this I get: The remote certificate is invalid according to the validation procedure.
smtpClient.Send(mailMessage);

我需要以不同于 smtp 服务器的方式处理交换服务器吗?

请指教
谢谢

最佳答案

您是否使用了正确的端口号?

Protocol: SMTP/SSL

•Port (TCP/UDP): 465 (TCP)

•Description: SMTP over SSL. TCP port 465 is reserved by common industry practice for secure SMTP communication using the SSL protocol. However, unlike IMAP4, POP3, NNTP, and HTTP, SMTP in Exchange 2000 does not use a separate port for secure communication (SSL), but rather, employs an "in-band security sub-system" called Transport Layer Security (TLS). To enable TLS to work on Exchange 2000, you must install a Computer certificate on the Exchange 2000 server.



从这里撕下: http://www.petri.co.il/ports_used_by_exchange.htm

关于c# - smtpclient 不适用于 Exchange 服务器,但适用于 smtp 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539976/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com