Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending mail with xp_sendmail

Status
Not open for further replies.

Linkan

Programmer
Feb 7, 2001
44
SE
Hello,
I have a website from where I want to send a formresult as a mail to the administrator of the site. I want send the email of the person who is logged in to the site as a replay address. I also want to send a subject and a message. The person who is sending is registered with a profile in the DB, that's from where I get the senders mail address.

I could use cdont but after reading I found out about xp_sendmail. I have an valid mailprofile in my sql but I dont know how to actually send my mail with xp_sendmail, how do I call it and how do I send my variables?

Thanks,
Linkan
 

You simply execute the extended stored procedure from your code as you would any SQL statement. The SQL statement would look like the following.

Exec master.dbo.xp_sendmail
@recipients='emailaddress@mailsite.com',
@subject='This is the subject...',
@message='This is the body of the message...'

Of course, there are a number of other parameters that you can use. Read SQL BOL for more detail.

You'll have to grant execute permissions on the procedure to the user or a role that that the user belongs to. One other thing to note is that the mail will be sent by the SQL Server using its profile rather than the user's profile. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks for your help, very helpful. So in other words if I want to send the mail with sender’s id I have to use cdont or something similar?
How does xp_sendmail handle big load of mail?

Thanks again,
Linkan
 

If you want the user ID on the Email, you should use something other than xp_sendmail.

We don't send large volumes of Email nor large files from SQL Server so I can't tell you anything about performance. I would be very cautious about using xp_sendmail to send a lot of mail. I don't think it is very efficient. However, that is based on casual observation. I don't have any data to back up my opinion. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Terry,

Thanks for your input it’s highly appreciated.
I will look for another solution.

Regards,
Linkan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top