MailMessage message = new MailMessage();
message.Subject = "test";
message.Body = "test";
message.To.Add("[email protected]");
message.From = new MailAddress("[email protected]");
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Host = "172.22.0.20";
smtp.Port = 25;
smtp.Send(message);
Any idea why I might be getting an error
The remote name could not be resolved.
Clearly no resolution is required as I have specified an IP address. I can ping the IP and even telnet on port 25 and successfully send an e-mail. But, I can't send an e-mail.
I ran a wireshark
trace and it doesn't look like any traffic is being send to 172.22.0.20
I use this code and its working fine on my end Make sure that you are using the correct IP Address and port number. I think your Port Number is not correct. (open your email id and check mail configuration)
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "this is email body";
SmtpClient client = new SmtpClient("172.22.0.20");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.Port = 25;
client.Send(mail);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With