Solved

Exchange for SQL server

Posted on 1998-08-21
4
177 Views
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 ?
0
Comment
Question by:Thabo
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1089683
Are you wanting to use the send_mail system stored proc?
0
 
LVL 4

Expert Comment

by:mcix
ID: 1089684
0
 
LVL 2

Expert Comment

by:threshold
ID: 1089685
Can you start up the SQLMail on Enterprise Manager?
0
 
LVL 2

Accepted Solution

by:
mkmccreary earned 100 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
FOR INSERT
AS
      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
      begin


            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
            begin
                  insert MailErrors ( lErrorCode, szErrorDescription, szRecipientName, szTableName, lRecordIdentity )
                        values ( @MailReturn, '', @ThisBox, 'Document', @TheKey)
            end

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

      



      close curInserted
      deallocate curInserted
GO

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

Good Luck,
Martin

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

839 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