I am having difficulty using xp_readmail in a stored procedure. I need to extract the subject line and message body from the email and then parse the subject line to identify some aspects and have the sp make some decisions about wether to store the email message body to a table. However, I am unable to get the subject line value from xp_readmail inot a variable I can manipulate. When I run the sp in query analyzer readmail returns the email values (so I know it is reading the emails) but the variable I am attempting to get th esubject into always comes back as null. What am I missing here??

The following is the last attempt at making this work:

CREATE PROCEDURE [dbo].[mailtest] AS

declare @subject varchar(250)
declare @status varchar(250), @message_id varchar(250), @originator varchar(50), @cc_list varchar(50), @query varchar(8000)

EXEC @status = master.dbo.xp_readmail
@originator = @originator OUTPUT,
@cc_list = @cc_list OUTPUT,
@subject = @subject OUTPUT,
@message = @query OUTPUT,
@peek = 'TRUE',
@suppress_attach = 'TRUE'

select @status as "mailstatus", @subject as "subject"