Emailing from SQL Server

  • Hi Guys

    I am really, really new to SQL Server and really need some help.

    I want to write a procedure that is scheduled to run on a daily basis.

    The query needs to performa simple query on one table and then send an email to particular users based on the query results.

    Basically, I really just need some help on how to email from a procedure. I've trolled round the net and found some code but none of it works (even though it compiles).

    Can someone give me some really easy simple help on how to send an email.

    As I've already said, I have never used SQL Server before.

    Thank you so much in advance.

  • Hi,

    you can any one of these two sp to send mail but for this outlook should be installed on your server.sometimes you can face some problem in outlook also.

    Run your query and take the out put into variables and send mail.

     

    EXEC  MASTER.DBO.XP_SENDMAIL

       @RECIPIENTS = @P_STRTO,

       @MESSAGE = @P_STRBODY,

       @QUERY = '',

       @ATTACHMENTS = '' ,

       @COPY_RECIPIENTS = '' ,

       @BLIND_COPY_RECIPIENTS = '' ,

       @SUBJECT = @P_STRSUBJECT 

     

     EXEC  MASTER.DBO.sp_smtp_sendmail

       @FROM       = @P_STRTO,

       ,@FROM_NAME  = N'GEAMSTDB01'

       ,@TO = @P_STRTO

       ,@message = @P_STRBODY

       ,@CC = ''

       ,@BCC =  ''

       ,@subject = @P_STRSUBJECT

       ,@attachments = ''

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

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