Search This Blog

How to read Mails using SQL Server

USE master 
DECLARE @status INT,
@MsgID VARCHAR(255),
@msg_id VARCHAR(255)
DECLARE @status2 INT
DECLARE @message VARCHAR(8000),
@dateRecive VARCHAR(255),
@subject VARCHAR(255)
DECLARE @subjectMessage VARCHAR(255),
@unread VARCHAR(5),
@UnreadFlag VARCHAR(5)
DECLARE @originator_address VARCHAR(255),
@SentBy VARCHAR(255)
DECLARE @i INT
DECLARE @attachments VARCHAR(255),
@attachmentsMessage VARCHAR(255)


EXEC @status2 = xp_findnextmsg @msg_id = @MsgID OUTPUT


WHILE @MsgID IS NOT NULL
BEGIN
EXEC @status = xp_readmail @msg_id = @MsgID ,
@originator_address = @SentBy OUTPUT ,
@unread = @UnreadFlag OUTPUT , @message = @message OUTPUT ,
@date_received = @dateRecive OUTPUT ,
@subject = @subjectMessage OUTPUT ,
@attachments = @attachmentsMessage OUTPUT


SELECT @message ,@dateRecive ,@subjectMessage ,@UnreadFlag ,@SentBy ,@attachmentsMessage
EXEC @status2 = xp_findnextmsg @msg_id = @MsgID OUTPUT

END


No comments: