Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,
I have very basic question, i have a domain name for example yahoo.in with me. Now, i want to pass that domain name and get SMTP mail server name for example smtp.mail.yahoo.com. I want to get this by c# code.
Means, i want dynamic SMTP name fetch by passing domain name.
My intention behind this, i have multiple of email addresses so i will pass domain name for a requested email address and fetch SMTP mail server name.
Please suggest code to get SMTP name by domain name.
Thanks in advance.
Posted

1 solution

You can use ARSoft.Tools.Net library to get the available SMTP servers for domain.
It's available on NuGet Packages:
C#
PM> Install-Package ARSoft.Tools.Net

Import the namespace:
C#
using ARSoft.Tools.Net.Dns;

Then make a synchronous lookup as:
C#
var response = DnsClient.Default.Resolve("yourdomain.com", RecordType.Mx);
var records = response.AnswerRecords.OfType<mxrecord>();
foreach (var record in records) {
    Console.WriteLine(record.ExchangeDomainName);
}
</mxrecord>

Which will give output like :
C#
mail1.yourdomain.com
mail2.yourdomain.com
mail3.yourdomain.com
mail4.yourdomain.com

Full documentation is available Here[^]
 
Share this answer
 
Comments
Member 8090436 9-Nov-15 3:37am    
Hi,
I am not able to get response from below code-
var response = DnsClient.Default.Resolve("yourdomain.com", RecordType.Mx);
var records = response.AnswerRecords.OfType<mxrecord>();
foreach (var record in records) {
Console.WriteLine(record.ExchangeDomainName);
}
I have added assembly.but, unable to fill response var variable.
[no name] 16-Nov-15 2:37am    
Did you gave your domain name instead of "yourdomain.com" ?

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