Solved

xp_sendmail error in Insert Trigger

Posted on 2004-08-26
10
426 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
Viewers will learn how the fundamental information of how to create a table.

726 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