我已使用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.
答案 0 :(得分:0)
client.UseDefaultCredentials
应设置为false
;