MailBee.NET Objects 7.1

Smtp.GetTxtData Method 

Retrieves the list of TXT strings of DNS data of the specified domain.

public string[] GetTxtData(
   string domain
);

Parameters

domain
The domain to get the list of MX hosts for.

Return Value

The array of strings taken from DNS TXT data of the specified domain, or a null reference (Nothing in Visual Basic) if an error occurred or no TXT record found for the given domain.

Remarks

This method makes DNS TXT query to the servers listed in DnsServers collection regarding domain. The method supports multiple strings per TXT record and multiple TXT records per domain. If multiple TXT records are returned, their arrays of strings are concatenated into single array.

TXT records contain important DNS information used by various antispam techniques like SPF and DomainKeys (DKIM).

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptiondomain is a null reference (Nothing in Visual Basic).
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample retrieves TXT information for "gmail.com" domain.

[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    static void Main(string[] args)
    {
        Smtp mailer = new Smtp();
        mailer.DnsServers.Autodetect();
        string[] strings = mailer.GetTxtData("gmail.com");
        foreach (string str in strings)
        {
            Console.WriteLine(str);
        }
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail

Class Sample
    Shared Sub Main(ByVal args() As String)
        Dim mailer As Smtp = New Smtp
        mailer.DnsServers.Autodetect()
        Dim strings() As String = mailer.GetTxtData("gmail.com")
        Dim str As String
        For Each str In strings
            Console.WriteLine(str)
        Next
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | GetMXHosts | GetPtrData