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

本文关键字:SMTP 电子邮件 失败 服务器 我自己 自己的 | 更新日期: 2023-09-27 18:27:33

我已经使用MailEnable设置了Mail Server,并使用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.

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

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