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
 
This is the basic syntax of it found in BOL:


xp_sendmail
Sends a message and a query result set attachment to the specified recipients.

Syntax
xp_sendmail {[@recipients =] 'recipients [;...n]'}
[,[@message =] 'message']
[,[@query =] 'query']
[,[@attachments =] 'attachments [;...n]']
[,[@copy_recipients =] 'copy_recipients [;...n]'
[,[@blind_copy_recipients =] 'blind_copy_recipients [;...n]'
[,[@subject =] 'subject']
[,[@type =] 'type']
[,[@attach_results =] 'attach_value']
[,[@no_output =] 'output_value']
[,[@no_header =] 'header_value']
[,[@width =] width]
[,[@separator =] 'separator']
[,[@echo_error =] 'echo_value']
[,[@set_user =] 'user']
[,[@dbuse =] 'database']



Hope this gets you started....
 
And here are a couple of examples from BOL on how you can use it:


Examples
A. Use xp_sendmail with no variables
This example sends a message to user Robert King (e-mail is robertk) that the master database is full.

EXEC xp_sendmail 'robertk', 'The master database is full.'

B. Use xp_sendmail with variables
This example sends the message to users Robert King and Laura Callahan (e-mail is laurac), with copies sent to Anne Dodsworth (e-mail is anned) and Michael Suyama (e-mail is michaels). It also specifies a subject line for the message.

EXEC xp_sendmail @recipients = 'robertk;laurac',
@message = 'The master database is full.',
@copy_recipients = 'anned;michaels',
@subject = 'Master Database Status'

C. Send results
This example sends the results of the sp_configure to Robert King.

EXEC xp_sendmail 'robertk', @query = 'sp_configure'

D. Send results as an attached file
This example sends the results of the query SELECT * FROM INFORMATION_SCHEMA.TABLES as a text file attachment to Robert King. It includes a subject line for the mail and a message that will appear before the attachment. The @width parameter is used to prevent line breaks in the output lines.

EXEC xp_sendmail @recipients = 'robertk',
@query = 'SELECT * FROM INFORMATION_SCHEMA.TABLES',
@subject = 'SQL Server Report',
@message = 'The contents of INFORMATION_SCHEMA.TABLES:',
@attach_results = 'TRUE', @width = 250

 
Thanks but I have read all that, I still dont know how I call this SP from my asp page where I have a form I want to send on submit.

Thanks,
Linkan
 
The best way I know of to call stored procedures and such from ASP is to use the Command object of ADO. You could either try to call xp_sendmail directly or you could create your own stored procedure and call it from the command object and pass it the values you want to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top