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

时间:2014-10-22 20:48:33

标签: c# .net email smtp

我已使用Mail Server设置了MailEnable并将我的域名配置为我的DNS名称(我正在使用dlinkddns帐户)和Outlook,我的帐户在收到电子邮件时工作正常,但电子邮件是已发送 - 我无法在其他邮箱中看到(我尝试使用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.

1 个答案:

答案 0 :(得分:0)

如果您提供凭据,

client.UseDefaultCredentials应设置为false;