Sample code for 30+ languages & platforms
SQL Server

Send to a File-Based Distribution List

See more Email Object Examples

Demonstrates the Chilkat Email.FileDistList property. Set this property to send an email to a list of recipients stored in a plain-text file — one recipient per line, blank lines ignored, no comments. Setting it is equivalent to adding a CKX-FileDistList header field. When the email is sent, MailMan reads the file and delivers to each recipient. This example sets the distribution-list file and prints the MIME.

Background: MIME headers whose names start with X- are non-standard, application-specific fields. Chilkat extends this idea with its own CKX- prefix: these fields let you attach instructions to an email object that Chilkat understands, but they are stripped before transmission so they never appear in the delivered message. They are preserved when you save/load the email as XML or MIME, making them handy for storing send-time metadata like a distribution list.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    --  Demonstrates the Email.FileDistList property.
    --  Setting this property causes MailMan to send the email to a list of
    --  recipients stored in a plain-text file (one recipient per line).
    --  Setting it is equivalent to adding a CKX-FileDistList header field.

    DECLARE @email int
    EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @email, 'Subject', 'Newsletter'
    EXEC sp_OASetProperty @email, 'Body', 'Hello subscribers!'
    EXEC sp_OASetProperty @email, 'From', 'news@example.com'

    --  The file contains one recipient email address per line.
    EXEC sp_OASetProperty @email, 'FileDistList', 'qa_data/txt/recipients.txt'


    EXEC sp_OAGetProperty @email, 'FileDistList', @sTmp0 OUT
    PRINT 'FileDistList = ' + @sTmp0

    --  The CKX-FileDistList header field is present in the saved MIME, but CKX-
    --  fields are never transmitted when the email is actually sent.
    EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @email


END
GO