C# 使用我自己的服务器发送SMTP电子邮件失败

C# 使用我自己的服务器发送SMTP电子邮件失败,c#,.net,email,smtp,C#,.net,Email,Smtp,我已经使用MailEnable设置了Mail服务器,并使用Outlook将我的域名配置为我的DNS名称(我使用的是dlinkddns帐户),我的帐户在收到电子邮件但发送的电子邮件时工作正常-我无法在其他邮箱中看到(我尝试Gmail) 现在我想做的就是使用.Net发送电子邮件,这就是我尝试过的: private string from = MyUser@MyDomain; MailMessage mail = new MailMessage(); mail.Subject = "My subje

我已经使用
MailEnable
设置了
Mail服务器
,并使用
Outlook
将我的域名配置为我的DNS名称(我使用的是dlinkddns帐户),我的帐户在收到电子邮件但发送的电子邮件时工作正常-我无法在其他邮箱中看到(我尝试Gmail)

现在我想做的就是使用
.Net
发送电子邮件,这就是我尝试过的:

private string from = MyUser@MyDomain;

MailMessage mail = new MailMessage();
mail.Subject = "My subject";
mail.Body = "My body";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient(MyDomain);
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential(from, myPassword);

try
{
    client.Send(mail);  
}
catch (Exception ex)
{
     MessageBox.Show(ex.Message, "Error");
}
这是收到的错误:

Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.

如果您提供凭据,则应将
client.UseDefaultCredentials
设置为
false

将其更改为false后仍然失败,并出现相同的错误错误该错误表明您甚至没有尝试进行身份验证,并且在将UseDefaultCredentials设置为false后仍然得到完全相同的结果?根据快速谷歌搜索。。。将身份验证类型从“MailEnable集成身份验证”更改为“根据以下用户名/密码进行身份验证”。然后输入用户名和密码。将“MailEnable集成身份验证”更改为“根据以下用户名/密码进行身份验证”是什么意思?我在我的代码中找不到它,我建议问题不在代码中,而是在MailEnable配置中。