Mail is not available. Server response: There is no such domain in this place

I use the following base code:

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));
}

The problem is that mail is only sent to my domain address ( someone@mydomain.com ), and I get the following exception for the other two addresses:

System.Net.Mail.SmtpFailedRecipientException: The mailbox is unavailable. Server response: There is no such domain in this place

I suspect this has something to do with something blocking my smtp client, but not sure how to approach this. Any ideas? thank!

+3
source share
2 answers

Ron is right, just use port 587 and it will work as you want.

Check out this code and see if it works:

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());
            }
        }
    }
}
+3
source

All Articles