Solved

Exchange for SQL server

Posted on 1998-08-21
4
170 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now