Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

Below are my working code-

MailMessage mail = new MailMessage();
mail.To.Add("test@domainname.com");
string fromEmail = "test@yahoo.in";
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.mail.yahoo.com";
smtp.Credentials = new System.Net.NetworkCredential("test@yahoo.in", "*********");
smtp.EnableSsl = true;
smtp.Send(mail);

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.
Posted
Comments
Debojyoti Saha 9-Nov-15 6:33am    
You need to find a SMTP server depends on domain. Please check the link
http://mailsystem.codeplex.com/SourceControl/changeset/view/52213#541648
Member 8090436 9-Nov-15 7:54am    
Thanks. I have tried to run the code but found it was having not completely running code.Lot many classes have not referenced available there.
Please suggest some other approach.
Thanks!

1 solution

You may refer to this SO post:
Finding the MX Record using C#?[^]

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900