|
nukeawhale
Starting Member
14 Posts |
Posted - 2003-11-13 : 14:12:45
|
| I am trying to use CDONTS to send mail using a stored procedure. However, the body of the message needs to be the result of query from a SQL table.I can successfully send mail using CDONTS with the sproc, but I can not get the results of the query to be in the body of the message .I am using the following sproc to send mail:CREATE PROCEDURE [dbo].[stp_NewMail] @From varchar(100),@To varchar(100),@Subject varchar(100),@Body varchar(4000),@CC varchar(100) = null,@BCC varchar(100) = null,@Imp int,@BodyFormat int,@MailFormat intASDeclare @MailID intDeclare @hr intEXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUTEXEC @hr = sp_OASetProperty @MailID, 'From',@FromEXEC @hr = sp_OASetProperty @MailID, 'To', @ToEXEC @hr = sp_OASetProperty @MailID, 'Subject',@SubjectEXEC @hr = sp_OASetProperty @MailID, 'Body', @BodyEXEC @hr = sp_OASetProperty @MailID, 'CC', @CCEXEC @hr = sp_OASetProperty @MailID, 'Bcc', @BCCEXEC @hr = sp_OASetProperty @MailID, 'Importance', @Imp --See Notes BelowEXEC @hr = sp_OASetProperty @MailID, 'BodyFormat', @BodyFormat --See Notes BelowEXEC @hr = sp_OASetProperty @MailID, 'MailFormat', @MailFormat --See Notes BelowEXEC @hr = sp_OAMethod @MailID, 'Send', NULLEXEC @hr = sp_OADestroy @MailIDTo send the mail I use the following command:EXEC stp_NewMail/*FROM*/ 'you@you.com', /* TO */ 'me@me.com', /* SUBJECT */ 'New Mail', /* BODY */ 'My message', /* CC */ '',/* BCC */ '',/* Importance */ 2,/* BODYfmt*/ 0,/* Mailfmt*/ 0How do I get the results of a query in the message of the body?Just a simple query like (SELECT TOP 5 * FROM tblMytbl)?I tried to create a variable to capture the results, but it's not working.I was using this with xp_sendmail and the @query variable, but am having access errors and other errors now which is causing it to fail. I would rather convert to CDONTS if it is possible instead of using xp_sendmail.Any help would be greatly appreciated. |
|