This topic is locked

email with my code

2/7/2008 11:37:15 AM
ASPRunnerPro General questions
T
Tim author

Hello,
I need to send email, but I am not asking users to login (I'm using Windows integrated auth.). It seems that ASPRunner only sends email if you set up smtp info in the Security page. "No problem, I'll write my own code" I thought. Here is the code I added to After Record Added:
Set myMail=CreateObject("CDO.Message")

myMail.Subject=dict("Subject")

myMail.From="tech@mndigerati.com"

myMail.To=dict("SendTo")

myMail.Cc=dict("Cc")

myMail.TextBody=dict("Body")

myMail.Send

set myMail=nothing
When I attempt to save the record I get the following error:
EXECUTE permission denied on object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
This confuses me because I wouldn't think the DB server had anything to do with sending the email. Am I worng about that? Also, the record is not added, which also seems odd because the send email code should execute after that.
One last piece of info; I can put my code in a test.asp page on my web server - changing the "dict" variables to hard coded entries - and it is sent without any problems.
Thanks for any help,

Tim

T
Tim author 2/7/2008

I fixed it! FYI to anyone else... the user I use for the DSN connection needed the DatabaseMailUserRole role on the msdb system database on my SQL2005 server. I'm still a bit confused by this; why is the database sending the email and not the web server? But whatever, it works now!
Tim