(SQL Server) MX Lookup Mail Server Domain by Email Address
How to find the mail server for a given email address. Returns the domain name of the primary mail server.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @mailman int
-- Use "Chilkat_9_5_0.MailMan" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @mxDomain nvarchar(4000)
EXEC sp_OAMethod @mailman, 'MxLookup', @mxDomain OUT, 'support@chilkatsoft.com'
EXEC sp_OAGetProperty @mailman, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mailman
RETURN
END
PRINT 'MX Domain: ' + @mxDomain
EXEC @hr = sp_OADestroy @mailman
END
GO
|