c# - 信箱不可用。服务器响应是 : No such domain at this location

标签 c# smtp

我正在使用以下基本代码:

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

msg.to.add("someone@hotmail.com");
msg.to.add("someone@gmail.com");
msg.to.add("someone@myDomain.com");

msg.From = new MailAddress("me@myDomain.com", "myDomain", System.Text.Encoding.UTF8);
msg.Subject = "subject";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;

//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Host = "192.168.0.24"; 
client.Credentials = new System.Net.NetworkCredential("me@myDomain.com", "password");
client.Port = 25;

try
{
   client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
    sw.WriteLine(string.Format("ERROR MAIL: {0}. Inner exception: {1}", ex.Message,  ex.InnerException.Message));
}

问题是邮件只发送到我域中的地址 (someone@mydomain.com),我得到以下 2 个其他地址的异常:

System.Net.Mail.SmtpFailedRecipientException: 邮箱不可用。服务器响应是:此位置没有这样的域

我怀疑这与阻止我的 smtp 客户端的东西有关,但不确定如何解决这个问题。 任何的想法?谢谢!

最佳答案

Ron 是正确的,只需使用 587 端口,它就会如您所愿地工作。

检查这段代码,看看它是否有效:

using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("to_address@mfc.ae");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

关于c# - 信箱不可用。服务器响应是 : No such domain at this location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10592026/

相关文章:

c# - 仅当 DataGridView 中的 Cell ValueChanged 时如何运行 Run CellEndEdit

c# - VR 添加运动 : Walk

php - zf2 - gmail smtp 不工作

c# - 通过 C# 和 IIS smtp 发送电子邮件时发送多个 header

email - 在回复/转发中总是返回哪些 header ?

c# - 删除 Global.asax 仍在执行的代码

c# - 什么是NullReferenceException,如何解决?

c# - 如何确定 SteamVR_TrackedObject 是 Vive Controller 还是 Vive Tracker

c# - SMTP.SendAsync 无法正常工作

python - 在 Python 中使用 SMTP 发送电子邮件