gpt4 book ai didi

c# - 发送邮件 Asp.Net 时出现 "Authentication failed"错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:03 24 4
gpt4 key购买 nike

搜索了很多网站都没有找到答案

我正在使用 VS2010(框架工作 4.0)和 SQL 2012,我们正在使用交换服务器....相同的邮件配置在 java 应用程序中工作但在 c# 中不工作

按钮点击代码是:

    try
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.myorganization.com"
smtp.Port = "587";
smtp.Credentials = new System.Net.NetworkCredential("abc@myorganization.com", "password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@myorganization.com");
msg.To.Add(new MailAddress("receiver@something.com"));
msg.Subject = "Test";
msg.Body = "Test mail";
smtp.Timeout = 60000;
smtp.Send(msg);
result = true;
}
catch (Exception ex)
{

}

我的异常错误是

System.Net.Mail.SmtpException was caught
HResult=-2146233088
Message=Authentication failed.
Source=System
StackTrace:
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at MailConfiguration.TestMail() in

最佳答案

我有一个非常相似的问题。尝试使用 wireshark 来了解出了什么问题。在我的例子中,我使用 System.Web.Mail 解决了这个问题。我知道它已被弃用,但您的情况与我的相似,我认为没有其他可能性可以解决该问题。

my solution

System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Body = message.Body;

string smtpServer = "mail.business.it";
string userName = "username";
string password = "password";
int cdoBasic = 1;
int cdoSendUsingPort = 2;
if (userName.Length > 0)
{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
}
msg.To = message.Destination;
msg.From = "me@domain.it";
msg.Subject = message.Subject;
msg.BodyFormat = MailFormat.Html;//System.Text.Encoding.UTF8;
SmtpMail.SmtpServer = smtpServer;
SmtpMail.Send(msg);

关于c# - 发送邮件 Asp.Net 时出现 "Authentication failed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33076064/

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