Sql Mail Procedure

  • Hi All,

    Im making an attempt at this for the first time through Visual Studio, I am not getting an error but not getting an email sent out either. Can anyone see what is wrong here?

    ALTER PROCEDURE dbo.StoredProcedureMail

    @P_To as varchar(50) = 'email@.com',

    @P_From as varchar(50) = '',

    @P_MailSubject as varchar(50) = '',

    @P_MailBody as varchar(MAX) = ''

    AS

    BEGIN

    DECLARE @To as varchar(50) = @P_To,

    @From as varchar(50) = @P_From,

    @MailSubject as varchar(50) = @P_MailSubject,

    @MailBody as varchar(MAX) = @P_MailBody

    EXECUTE [msdb].[dbo].[sp_Send_dbmail]

    @profile_name = 'SQL_Server',

    @recipients = @To,

    @FromTextBox = @From,

    @SubjectTextBox = @MailSubject,

    @body_format='HTML',

    @MessageTextBox = @MailBody

    RETURN

    END

    Thanks!

  • First questions would be can you use sp_send_mail outside of the procedure? if not, then it could be you have a bad mail server dns name configured. Then I would ask if the mail profile SQL_Server is set up on the server (except that should toss an error).

  • I'll have to check on if I can send outside of the procedure when I not behind the firewall. But I did figure out that because I am using visual studio 2010 that I had to change the master db to allow it to send mail, then I think my next step is to add a user account. I can see where my parameters are being passed into the stored procedure when I simply execute it and type in a test message etc.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply