BUG: Error 18009 When Calling xp_readmail Stored Procedure with @suppress_attach Parameter

ID: Q184038


The information in this article applies to:


SYMPTOMS

When you call the xp_readmail extended stored procedure with the @suppress_attach = 'true' parameter and do not specify the @msg_id parameter, you receive the following error message when xp_readmail tries to read an e-mail message that contains an attachment:

Error : 18009, Severity: 18, State: 1
Exception error encountered in MAPI extended procedures, exception
error code = 0xC0000005


WORKAROUND

If you call xp_readmail and provide the @msg_id parameter, the server does not generate the exception error. You can use the following code sample to get the @msg_id parameter and then use it to call the xp_readmail extended stored procedure.

Sample Code

This code allows you to get the parameter which will call the extended stored procedure correctly.

   declare @count           int
   declare @status          int
   declare @msg_id          varchar(64)
   declare @subject         varchar(255)
   declare @message         varchar(255)
   declare @recipients      varchar(255)
   declare @cc_list         varchar(255)
   declare @bcc_list        varchar(255)
   declare @date_received   varchar(255)
   declare @unread          varchar(255)
   declare @attachments     varchar(255)
   declare @skip_bytes      int
   declare @msg_length      int
   declare @fDone           bit
   declare @fRead           bit

   select @fDone = 0
   select @skip_bytes = 0
   select @count = 0

   while (1 = 1)
   begin
      exec @status = xp_findnextmsg @msg_id = @msg_id output
      select "status after xp_findnextmsg"
      select @status
      if @status <> 0
      begin
         select @fDone = 1
         print "status = 0"
         break
      end
      if @msg_id = NULL
      begin
         select @fDone = 1
         print "msg_id = NULL"
         break
      end
      select @fRead = 0

      exec @status = xp_readmail
         @msg_id       = @msg_id,
         @suppress_attach   = 'true',
         @subject       = @subject output,
         @message       = @message output,
         @unread       = @unread output,
         @skip_bytes       = @skip_bytes output,
         @msg_length       = @msg_length output

      select "status after xp_readmail = ", @status
      select "unread = ", @unread
      if @status <> 0
      begin
         select @fRead = 1
         select "status = 0"
         break
      end

      select "msgid" = @msg_id, "msg part" = @message
      select "skipped bytes", @skip_bytes
      select "msg_length", @msg_length

      select @subject

      select @count = @count + 1
   end
   go 


STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: msgread AV MAPI


Keywords          : SSrvGPF SSrvStProc SSrvTran_SQL 
Version           : WinNT:6.5
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: April 21, 1999