Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    5

    Unanswered: Mail attachment with CDOSYS

    Hi,
    I am using the following stored procedure to send a mail with attachment. But the mail is sent without the attachment. Can anyone help me?

    CREATE PROCEDURE DBO.sp_Send_Mail_test(
    @p_From as nvarchar(50),
    @p_To as nvarchar(50),
    @p_Subject as nvarchar(255),
    @p_Body as varchar(1000),
    @p_CC as text = null,
    @p_BCC as text = null,
    @p_Attachment varchar(500)=null
    )
    AS
    Declare @Message int
    Declare @hr int
    Declare @source varchar(255)
    Declare @description varchar(500)

    EXEC @hr = sp_OACreate 'CDO.Message', @Message OUT

    EXEC @hr = sp_OASetProperty @Message, 'From',@p_From

    EXEC @hr = sp_OASetProperty @Message, 'To', @p_To

    EXEC @hr = sp_OASetProperty @Message, 'Subject', @p_Subject

    EXEC @hr = sp_OASetProperty @Message, 'TextBody', @p_Body

    EXEC @hr = sp_OAMethod @Message, 'CDO.Message.Attachment.Update', Default, @p_Attachment

    If @p_CC is not null
    BEGIN
    EXEC @hr = sp_OASetProperty @Message, 'CC',@p_CC
    END

    If @p_BCC is not null
    BEGIN
    EXEC @hr = sp_OASetProperty @Message, 'BCC',@p_BCC
    END

    EXEC @hr = sp_OAMethod @Message, 'Send', NULL

    EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description out


    EXEC @hr = sp_OADestroy @Message
    IF @hr <> 0
    BEGIN
    SELECT hr=convert(varbinary(4),@hr), Source=@source, Description=@description
    RETURN
    END

    Regards,
    Bharathram G

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    My first guess would be that you didn't use a UNC for the file name.

    I'm moving this post to the SQL Server Forum for you... I think that you'll get a lot better responses there than you will in a "pure SQL" forum.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •