Mangesh barmate

Mangesh barmate

  • 2.1k
  • 118
  • 129.6k

Get SMTP detail from domain name in c#?

Nov 9 2015 6:17 AM

Hi Team,

Below are my working code-

MailMessage mail = new MailMessage();
string fromEmail = "";
mail.From = new MailAddress(fromEmail);
string[] split = fromEmail.Split('@');
string domainName = split[1].ToString();

mail.Subject = "Email using any SMTP";

string Body = "Hi, this mail is to test sending mail" + "using any SMTP in ASP.NET";
mail.Body = Body;

mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "";
smtp.Credentials = new System.Net.NetworkCredential("", "*********");
smtp.EnableSsl = true;

This code is perfectly working for Yahoo SMTP server. Now what is my requirement here,

suppose, i have hotmail,gmail or any other email address, i will get it Domain Name into domainName variable. I want to get SMTP mail server name on that Domain Name and pass it to smtp.Host value. In this way i want to keep my code dynamic.

Can anyone suggest me the approach for how to get SMTP mail server name on the base of Domain Name?

Please suggest.

Answers (1)