Exchange for SQL server

Posted on 1998-08-21
Medium Priority
Last Modified: 2010-05-18
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 ?
Question by:Thabo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 1089683
Are you wanting to use the send_mail system stored proc?

Expert Comment

ID: 1089685
Can you start up the SQLMail on Enterprise Manager?

Accepted Solution

mkmccreary earned 300 total points
ID: 1089686
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,


Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question