Hi all,
I am using the stored procedure below to send emails. It was posted by Colin Leversuch-Roberts on the web.
It works very well, I get the emails, but without the attachment. Is it because of the file path I have given which is on my local machine? Should the file be on the database server? I don't know much about database server stuff.
Any help is appreciated,
thanks,
Shal
exec sp_send_cdontsmail 'your.account@your-company.com', 'another.account@another-company.com', 'Inbound File', 'Please find attached Inbound Export.', null, null, 'C:\Documents and Settings\Shal\My Documents\testwrite.txt'
CREATE PROCEDURE [dbo].[sp_send_cdontsmail]
@From varchar(100),
@To varchar(100),
@Subject varchar(100),
@Body varchar(4000),
@CC varchar(100) = null,
@BCC varchar(100) = null,
@Attachment varchar(150) = null
AS
Declare @MailID int
Declare @hr int
print @attachment
EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
EXEC @hr = sp_OASetProperty @MailID, 'From',@From
EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @MailID, 'To', @To
EXEC @hr = sp_OASetProperty @MailID, 'MailFormat', 0 -- MIME format to ensure attachments are sent correctly via internet
EXEC @hr = sp_OAMethod @MailID, 'AttachFile', NULL, @Attachment
EXEC @hr = sp_OAMethod @MailID, 'Send', NULL
EXEC @hr = sp_OADestroy @MailID
GO
I am using the stored procedure below to send emails. It was posted by Colin Leversuch-Roberts on the web.
It works very well, I get the emails, but without the attachment. Is it because of the file path I have given which is on my local machine? Should the file be on the database server? I don't know much about database server stuff.
Any help is appreciated,
thanks,
Shal
exec sp_send_cdontsmail 'your.account@your-company.com', 'another.account@another-company.com', 'Inbound File', 'Please find attached Inbound Export.', null, null, 'C:\Documents and Settings\Shal\My Documents\testwrite.txt'
CREATE PROCEDURE [dbo].[sp_send_cdontsmail]
@From varchar(100),
@To varchar(100),
@Subject varchar(100),
@Body varchar(4000),
@CC varchar(100) = null,
@BCC varchar(100) = null,
@Attachment varchar(150) = null
AS
Declare @MailID int
Declare @hr int
print @attachment
EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
EXEC @hr = sp_OASetProperty @MailID, 'From',@From
EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @MailID, 'To', @To
EXEC @hr = sp_OASetProperty @MailID, 'MailFormat', 0 -- MIME format to ensure attachments are sent correctly via internet
EXEC @hr = sp_OAMethod @MailID, 'AttachFile', NULL, @Attachment
EXEC @hr = sp_OAMethod @MailID, 'Send', NULL
EXEC @hr = sp_OADestroy @MailID
GO