Exchange for SQL server

I would like to setup an exchange mailbox for sql server .
to be able to send mail messages from sql server using stored procedures . Will these work if yes , how can I do this ?
Who is Participating?
mkmccrearyConnect With a Mentor Commented:
First, the exchange client needs to be configured on the SQL server machine.  Then the SQL Server Mail needs to be configured through SQL Enterprise Manager.  There is an article on troubleshooting SQLMail and Exchange from Microsoft MSDN Article ID Q153159.  I have below a script on how to send mail during an insert trigger.  It is an insert into a table called 'Document'.  When the insert is made it determines which exchange mailbox to send a message to using the 'DocumentType' table and the field 'szQueueName' in this table.  These are just for standard mailboxes, this script does not work with public folders.  I am also using the 'Inserted' temp table to retrieve some of the information inserted and add it to the message.  The trigger code is:

/****** Object:  Trigger dbo.trigDocument_Insert    Script Date: 6/19/98 8:28:01 AM ******/
CREATE TRIGGER trigDocument_Insert ON dbo.Document
      declare @MailReturn int,
            @AMessage varchar(255),
            @TheKey int,
            @ThisBox varchar (255),
            @DocType varchar (255),
            @lDocType int,
            @CaseNumber int,
            @Description varchar (255)

      declare curInserted insensitive cursor
            for select Inserted.lPrimaryKey, lDocumentType, lCaseNumber, szDescription, szDocumentDescription, szQueueName
            From Inserted, DocumentType
            Where DocumentType.lPrimaryKey = lDocumentType

      open curInserted

      fetch curInserted into @TheKey, @lDocType, @CaseNumber, @Description, @DocType, @ThisBox

      while @@fetch_status = 0

            select @AMessage = ('Record Number = ' + convert(varchar(10),@TheKey) + '   Case Number = ' + convert(varchar(10),@CaseNumber) + '   Document Type = ' + @DocType + '   Description = ' + @Description + '    Queue Name = ' + @ThisBox)

            exec @MailReturn = master..xp_sendmail @recipients = @ThisBox,
                  @message = @AMessage,
                  @subject = 'SQL Mail Test'

            if @MailReturn <> 0
                  insert MailErrors ( lErrorCode, szErrorDescription, szRecipientName, szTableName, lRecordIdentity )
                        values ( @MailReturn, '', @ThisBox, 'Document', @TheKey)

            fetch curInserted into @TheKey, @lDocType, @CaseNumber, @Description, @DocType, @ThisBox


      close curInserted
      deallocate curInserted

It may become more readable if you cut and paste it into something else.

Good Luck,

Are you wanting to use the send_mail system stored proc?
Can you start up the SQLMail on Enterprise Manager?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.