Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 xp_readmail/findnextmsg just shows the 1st message

Author  Topic 

ajmufic
Starting Member

17 Posts

Posted - 2009-06-02 : 07:36:23
Trying to create a script that loops through all the emails in the inbox (and then I am supposed to perform certain operations, if certain data is found in the message).

However I can't get it to work. I found several sample codes to loop through the email but nothnig seems to work. If I just write "exec xp_readmail" all emails are listed but when I try for instance the following code:
DECLARE @status int
DECLARE @hMessage varchar(255)
DECLARE @MessageText varchar(8000)

EXEC @status = xp_findnextmsg @unread_only='false',@msg_id=@hMessage OUT

WHILE @status = 0
BEGIN
exec xp_readmail @msg_id=@hMessage, @message=@MessageText OUT

SELECT 'Message: ' + @MessageText

SET @hMessage = NULL

EXEC @status = xp_findnextmsg @unread_only='false',@msg_id=@hMessage OUT
END

which seems to have worked for others, I just get a loop showing the first message over and over again. It seems like a few others have had the same problem but I haven't found a solution.

Or do I have to delete every email, after having read it.....?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-02 : 08:31:55
Not sure but it looks like you must not set @hMessage to NULL because it is the offset to get the very next message.
BOL says it is an input and output parameter...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ajmufic
Starting Member

17 Posts

Posted - 2009-06-02 : 08:44:43
quote:
Originally posted by webfred

Not sure but it looks like you must not set @hMessage to NULL because it is the offset to get the very next message.
BOL says it is an input and output parameter...


No, you're never too old to Yak'n'Roll if you're too young to die.

You're absolutely right!!! I didn't check the code so thoroughly, since some people wrote that it worked for them. I thought I was a bug or something.

Thanks a lot!
Go to Top of Page
   

- Advertisement -