Solved

xp_sendmail error in Insert Trigger

Posted on 2004-08-26
10
427 Views
Last Modified: 2012-06-21
I am trying to use a Trigger to execute the xp_sendmail stored procedure so a notification message will be sent after a new record is inserted.  Here is the code I used to create the trigger:
CREATE TRIGGER [trgEmailGreg] ON [dbo].[tblRMR]
FOR INSERT

AS

exec xp_sendmail
@recipients = 'Brick, Greg',
@message = 'A new RMR has been submitted.  Please review and disposition as necessary',
@subject = 'New RMR submitted'

Every time I try to insert a record I get an error saying the xp_sendmail stored procedure cannot be found.
Why is this happening?
0
Comment
Question by:PsychoDazey
[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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 500 total points
ID: 11903308
try qualifying it with the dbname :

CREATE TRIGGER [trgEmailGreg] ON [dbo].[tblRMR]
FOR INSERT

AS

exec master..xp_sendmail
@recipients = 'Brick, Greg',
@message = 'A new RMR has been submitted.  Please review and disposition as necessary',
@subject = 'New RMR submitted'
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11903532
OK, now I get :
xp_sendmail failed with mail error 0x8004011d (# 18025)
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11904116
Have you set up your mail profile correctly?
check out here for info...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_1_server_0r1w.asp
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 34

Expert Comment

by:arbert
ID: 11905659
This is my favorite SQL mail configuration link:

http://support.microsoft.com/default.aspx?scid=kb;en-us;263556&Product=sql2k


Also, kind of a bad idea to call sendmail from a trigger--it can be slow and even lock up (causing blocks/locks on your table).  Usually a better idea to use a queue table or a scheduled job that looks for add/change dates and email that way.

Brett
0
 

Expert Comment

by:tmprice
ID: 11905971
like stated above, sending an email by a trigger isn't recommended.  If the email fails to send, for whatever reason, the transaction is rolled back.
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11906834
I will keep that in mind....but if I can't get it to work it wont help anyways :-P
I have read both articles listed above and the mail profile I set up tests fine.  I just dont know why it wont run for me.
0
 

Expert Comment

by:tmprice
ID: 11907034
I used an app called NetMailBot that is simply an executable that sends email based on parameters.   Used a sp to build the parameters and then execute the program.   then scheduled the sp to run every X minutes.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11907480
"If the email fails to send, for whatever reason, the transaction is rolled back."

Rolls back if you're lucky--most usually locks up and blocks the table....

if you run xp_sendmail from query analyzer, do you get the same error?  Can you open the outlook client on the SQL Server and test sending an email (use the SQLAgent Account to signon when you do it).
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11931113
Sorry, I was out of town for a few days.  
Yes arbert, I get the same error in query analyzer.
Yes, I can send and receive e-mail from that mail box on the server.
How would I create a job that runs this code rather than a trigger?  Is it the same syntax (minus the for insert)?
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11933612
I found out it was an issue with the way the account was configured in Exchange.
Since BillAn1's comment eliminated the original error message I was getting, I gave him the points.

Thanks all.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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
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 ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

688 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