Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.0.0+

Send an email with a Bcc recipient using SMTP (live send)

See more Email Object Examples

Live send. Load the previously prepared with-attachments.eml, add a Bcc recipient, and pass the Email to MailMan.SendEmail. For a real test, use a relay you control, replace the sample sender and recipients (including the Bcc address) with test mailboxes, and obtain credentials from your application’s secret store.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Assumes Chilkat is unlocked. See Global Unlock Sample.

    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_OAMethod @email, 'LoadEml', @success OUT, 'with-attachments.eml'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @email
        RETURN
      END
    --  Enable this option before adding a blind recipient to the message.
    EXEC sp_OASetProperty @email, 'UncommonOptions', 'NoBccHeader'
    EXEC sp_OAMethod @email, 'AddBcc', @success OUT, 'Bcc recipient', 'bcc@example.net'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @email
        RETURN
      END
    DECLARE @mail int
    EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mail OUT

    EXEC sp_OASetProperty @mail, 'SmtpHost', 'smtp.example.com'
    EXEC sp_OASetProperty @mail, 'SmtpPort', 465
    EXEC sp_OASetProperty @mail, 'SmtpSsl', 1
    EXEC sp_OASetProperty @mail, 'RequireSslCertVerify', 1
    EXEC sp_OASetProperty @mail, 'SmtpUsername', 'MAIL_USER'
    EXEC sp_OASetProperty @mail, 'SmtpPassword', 'MAIL_PASSWORD'
    EXEC sp_OAMethod @mail, 'SendEmail', @success OUT, @email
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mail, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @email
        EXEC @hr = sp_OADestroy @mail
        RETURN
      END

    PRINT 'The SMTP relay accepted the message.'
    EXEC sp_OAMethod @mail, 'CloseSmtpConnection', @success OUT
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mail, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @email
        EXEC @hr = sp_OADestroy @mail
        RETURN
      END

    EXEC @hr = sp_OADestroy @email
    EXEC @hr = sp_OADestroy @mail


END
GO