Xp_readmail (Transact-SQL)

Bir posta iletisi SQL Mail gelen kutusundan okur.Bu yordam tarafından kullanılır sp_processmail SQL Mail gelen tüm postaların işlenecek.

Not

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Topic link iconTransact-SQL sözdizimi kuralları

xp_readmail [ [ @msg_id= ] 'message_id' ]
     [ , [ @type= ] 'type' [ OUTPUT ] ] 
     [ , [ @peek= ] 'peek' ]
     [ , [ @suppress_attach= ] 'suppress_attach' ]
     [ , [ @originator= ] 'sender' OUTPUT ]
     [ , [ @subject= ] 'subject' OUTPUT ]
     [ , [ @message= ] 'message' OUTPUT ]
     [ , [ @recipients= ] 'recipients [ ;...n ]' OUTPUT ]
     [ , [ @cc_list= ] 'copy_recipients [ ;...n ]' OUTPUT ]
     [ , [ @bcc_list= ] 'blind_copy_recipients [ ;...n ]' OUTPUT ]
     [ , [ @date_received= ] 'date' OUTPUT ]
     [ , [ @unread= ] 'unread_value' OUTPUT ]
     [ , [ @attachments= ] 'attachments [ ;...n ]' OUTPUT ])
     [ , [ @skip_bytes= ] bytes_to_skip OUTPUT ]
     [ , [ @msg_length= ] length_in_bytes OUTPUT ]
     [ , [ @originator_address= ] 'sender_address' OUTPUT ] ]

Bağımsız değişkenler

  • [ @msg_id = ] 'message_id'
    Is the ID of the message to read.message_id is varchar(255), with no default.

  • [ @ türü = ] 'type'
    Dönmek için ileti türünü MAPI tanımına göre:

    IP[ M|C ].Vendorname.subclass

    If used on input, this must define the type for a specific message; type is ignored on input if message_id is NULL.type is varchar(255), with a default of NULL.SQL Mail ileti türlerini destekler. IPM ve IPC.

  • Çıktı
    Belirtildiğinde, belirtilen parametrenin değeri bir çıktı parametresinde yerleştirir.

  • [ @peek = ] 'peek'
    Is whether SQL Server returns the message of the mail without changing the mail status to read.peek is varchar(5), with a default of FALSE.küme Iletiyi okuyabilir ancak posta FALSE'olarak nitelenir.küme, TRUE olarak değil okuma karşın posta kabul edilir.

  • [ @suppress_attach = ] 'suppress_attach'
    Is whether mail attachments are suppressed.suppress_attachis varchar(255), with a default of FALSE.küme, TRUE olarak SQL Server geçici oluşturulmasını engeller, dosyaları Xp_readmail ekli bir iletiyi okur.küme Için YANLıŞ, hiçbir önlem geçici dosyaların yok ekleri olan iletiler okunduğunda.

  • [ @originator = ] 'sender'
    Is the returned mail sender.senderis varchar(255), with no default.

  • [ @subject = ] 'subject'
    Is the returned the subject of the mail message.subject is varchar(255), with no default.

  • [ @message = ] 'message'
    Is the returned body or the actual text of the mail message.message is text, with no default.

  • [ @recipients = ] 'recipients [ ;... n] '
    Noktalı virgüllerle ayrılmış döndürülmesi posta iletisi için alıcıları listesidir.Recipient names are separated by a semicolon (
    ;
    ).recipient_list is varchar(255), with no default.

  • [ @cc_list = ] 'copy_recipients [ ;... n] '
    Noktalı virgüllerle ayrılmış alıcıların BILGI üzerinde listesidir: alan posta iletisinin döndürülmesi. Recipient names are separated by a semicolon (
    ;
    ).cc_list is varchar(255), with no default.

  • [ @bcc_list = ] 'blind_copy_recipients[ ;... n] '
    Noktalı virgülle ayrılmış, GIZLI alıcılar için listesidir: alan posta iletisinin döndürülecek. Recipient' names are separated by a semicolon (
    ;
    ).bcc_list is varchar(255), with no default.E-posta sunucusu için GIZLI alan bir değer sonra sağlamaz blind_copy_recipients boş olur.

  • [ @date_received = ] 'date'
    Is the returned date of the mail message.date is varchar(255), with no default.

  • [ @unread = ] 'unread_value'
    Is whether a message has been previously unread (true) or not (false).unread_value is varchar(5), with a default of TRUE.

  • [ @attachments = ] 'attachments [ ;... n] '
    Noktalı virgüllerle ayrılmış iletiyi posta eklerini döndürülen geçici yollarını listesidir.Temporary paths are separated by a semicolon (
    ;
    ).attachments is varchar(255), with no default.

  • [ @skip_bytes = ] bytes_to_skipOUTPUT
    Bu parametre, 0 dışında bir değer girdisi geçirilir, iletinin sonraki 255 bayt (en çok) okumadan önce atlanacak bayt sayısını belirtir body_of_message parametre çıktı. When bytes_to_skip is used, body_of_message includes the next portion of the message and bytes_to_skip returns with the next starting point within the message (the previous bytes_to_skip plus the length of message).bytes_to_skip is int, with a default of 0.

  • [ @msg_length = ] length_in_bytesOUTPUT
    Iletinin, bayt cinsinden toplam anahtar uzunluğudur.When used with bytes_to_skip in a stored procedure, this parameter allows messages to be read in chunks of 255 bytes.length_in_bytes is int.

  • [ @originator_address = ] 'sender_address'
    Is the resolved mail address of the originator of the mail message.sender_address is varchar(255), with no default.

Dönüş Kodu Değerleri

0 (başarılı) veya 1 (hata)

Sonuç Kümeleri

Xp_readmail bu sütunları bir sonuç döndürür.

sütun Name

Açıklama

Kaynağı

Gönderenin e-posta iletisinin

Alınan tarih.

E-posta iletisinin alındığı tarih

Alıcılar

Iletinin gönderildiği kişiler

BILGI listesi

Kişiler, "CC:" e-posta iletisi satırı

GIZLI listesi

Kişiler, "GIZLI:" e-posta iletisi satırı

Konu

E-posta iletisinin konu satırında

İleti

Ileti gövdesi (metin)

Okunmamış

Bu iletinin okunmamış olup olmadığı

Ekleri

Iletinin herhangi bir ek

Ileti KIMLIĞI

Ileti KIMLIĞI

Tür

Ileti türü

Remarks

Geçersiz bir parametre dışında herhangi bir hata günlüğe kaydediliyor Microsoft Windows Uygulama günlüğü.

Kullanmanın iki yolu vardır. Xp_readmail:

  • Sonuç olarak gelen tüm iletileri geri dönmek küme istemcisine.

  • Tek bir iletinin, gelen kutusundan okuyun.

Sonuç olarak, istemciye ayarlamak gelen içeriğini geri dönmek için , Giriş parametreleri sağlar.

Varsayılanı değiştirmek için hata suppress_attach parametresini TRUE olarak, iki olası güvenlik sorunları için ekleri yükseltir.

  • Iki farklı kullanıcının aynı geçici dizini ve oturum açmak için aynı bilgisayarı paylaşıyorsa, ilk olarak, bunlar birbirlerinin ekleri mümkün olacaktır.Eklerin depolandığı ve gözden geçirerek iki kullanıcı aynı geçici dizini paylaştırmak olup olmadığını belirleyebilir attachments Çıkış değişkeni.

  • İkinci xp_deletemail bu ekleri silmez, bu nedenle, her ek el ile silmeniz gerekir.

Tek bir iletinin, gelen kutusundan okumak için , geçerli bir kaynağı message_id tarafından döndürüldü. xp_findnextmsg bir giriş parametresi olarakXp_readmail.Belirtebilirsiniz peek ve suppress_attach iletinin biçimini denetlemek için giriş parametresi okunur. Kullanırken peek ve suppress_attach Bu yöntemde, tüm diğer gelen iletinin okunması için özel bilgiler içeren isteğe bağlı çıkış parametrelerini parametreleridir.

Örnek kullanarak görebilirsiniz. xp_findnextmsg bir giriş parametresi olarakXp_readmail olarak, aşağıdaki komutu yürütülüyor:

sp_helptext 'sp_processmail';

Tek bir iletiyi okumak için kullanılan Xp_readmail bölümlerdeki 255 bayttan uzun ileti metni okuyabilirsiniz.Kullanımı length_in_bytes ileti metnini bölümlerdeki 255 bayttan uzun okumak için . Bu alternatif length_in_bytes Giriş ve bir çıkış parametresi, tüm ileti metni işlemek için döngü kodlama izin verir. Aşağıdaki kod örneği bu tür bir döngü gösterir varsayılıyor. message_id döndürülen bir geçerli bir ileti tanımlayıcısı için küme xp_findnextmsg.

USE master;
GO

-- Set up variables.

DECLARE @status INT,
        @message_part VARCHAR(255),
        @msg_id VARCHAR(255),
        @message_length INT,
        @skip_bytes INT,
        @message VARCHAR(MAX) ;

-- Find the next message

EXEC @status = dbo.xp_findnextmsg
     @msg_id = @msg_id OUTPUT ;


-- If xp_findnextmsg completed successfully and
-- there is a message in the inbox, read the message.

IF (@status = 0  AND @msg_id IS NOT NULL)
BEGIN
   WHILE (1=1)
   BEGIN
        EXEC @status = dbo.xp_readmail
             @msg_id = @msg_id,
             @msg_length = @message_length OUTPUT,
             @skip_bytes = @skip_bytes OUTPUT,
             @message = @message_part OUTPUT ;

        IF @status <> 0 BREAK ;

        SET @message = ISNULL(@message, '') + @message_part ;

        PRINT @message_length ;
        PRINT @skip_bytes;

        IF @message_length = @skip_bytes BREAK ;

    END ;
    
    IF @status = 0
    BEGIN
       SELECT 'Message ID' = @msg_id, 'Message Body' = @message ;
    END ;
    ELSE
        SELECT 'Could not read message.' ;
END;

GO

İzinler

Üyelik gerektirir sysadmin sabit sunucu rolü, ancak yürütmek izinleri, diğer kullanıcılar için verilebilir.Ancak, güvenlik nedenleriyle Bu saklı yordam için izinleri üyelerine sınırlı olmasını öneririz sysadmin sabit sunucu rolü.

Örnekler

Aşağıdaki örnek, bir iletiyi okurken durumu döndürür.Örneğin, bir iletinin KIMLIK değeri xp_findnextmsg yerel değişken olarak verilen @message\_id geçirilen için ve xp_readmail.

USE master ;
GO

DECLARE @status INT,
    @msg_id VARCHAR(255),
    @originator VARCHAR(255),
    @cc_list VARCHAR(255),
    @subject VARCHAR(255),
    @query VARCHAR(8000);


-- Find the next message

EXEC @status = dbo.xp_findnextmsg
     @msg_id = @msg_id OUTPUT ;


-- If xp_findnextmsg completed successfully and
-- there is a message in the inbox, read the message.

IF (@status = 0  AND @msg_id IS NOT NULL)
BEGIN
    EXEC @status = dbo.xp_readmail
        @msg_id = @msg_id,
        @originator = @originator OUTPUT,
        @cc_list = @cc_list OUTPUT,
        @subject = @subject OUTPUT,
        @message = @query OUTPUT,
        @peek = 'TRUE',
        @suppress_attach = 'TRUE'

END;
GO