Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exchange for SQL server

Posted on 1998-08-21
4
Medium Priority
?
182 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
[X]
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
4 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1089683
Are you wanting to use the send_mail system stored proc?
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 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

636 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