Post Content

Ability to send an email from a MSSQL Stored Procedure

http://www.sqldev.net/xp/xpsmtp.htm

Installation[-][--][++]

  1. Download the attached .zip and extract
  2. Copy the xpsmtp80.dll to C:\Program Files\Microsoft SQL Server\MSSQL\Binn
  3. Run this procedure on the servers master database
    exec sp_addextendedproc 'xp_smtp_sendmail', 'xpsmtp80.dll'
    
  4. Use this syntax for a simple email
    DECLARE @rc INT
    EXEC @rc = master.dbo.xp_smtp_sendmail
        @FROM       = N'from@email.com',
        @FROM_NAME  = N'fromname',
        @replyto    = N'replyto@email.com',
        @TO         = N'to@email.com',
        @subject    = N'Your Subject Here',
        @type       = N'text/html', 
        @message    = N'Your HTML body here',
        @timeout    = 10000,
        @server     = N'Your SMTP Server Here'
    SELECT RC = @rc