2026-07-15

Adding Bcc to Email sending using .NET SmtpClient?

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

Adding Bcc to Email sending using .NET SmtpClient?

Adding BCC to Email Sending using .NET SmtpClient: A Developer's Guide

Sending emails programmatically is a fundamental task in almost any backend application. When leveraging the .NET framework, specifically classes like SmtpClient and MailMessage, developers often need fine-grained control over email headers, including managing recipients via To, CC, and especially BCC (Blind Carbon Copy).

This guide will walk you through the precise method for adding BCC recipients to a MailMessage instance when sending emails via SMTP in C#. Understanding how these headers are structured is crucial for ensuring your emails are delivered correctly and securely.

Understanding Email Headers: To, CC, and BCC

Before diving into the code, it’s important to understand the role of each field:

  1. To: The primary recipient(s) of the email.
  2. CC (Carbon Copy): Recipients who receive a copy of the email, and everyone else can see that they received it.
  3. BCC (Blind Carbon Copy): Recipients who receive a copy of the email, but their address is hidden from all other recipients, including those in the To and CC fields. This is ideal for mass communications where privacy is required.

The core challenge when using .NET’s MailMessage is that it provides explicit properties for To and CC, and a property specifically for Bcc.

Implementing BCC with MailMessage in C#

Adding a BCC recipient to a MailMessage instance is straightforward, though it requires careful handling of the recipient list. You must ensure that all recipients (To, CC, and BCC) are properly added as MailAddress objects before sending.

Here is a practical example demonstrating how to construct a MailMessage with both standard recipients and a hidden BCC address.

using System;
using System.Net.Mail;
using System.Net;

public class EmailSender
{
    public void SendEmailWithBcc()
    {
        // 1. Define the primary recipients (To)
        string toEmail = "primary@example.com";
        MailAddress toAddress = new MailAddress(toEmail);

        // 2. Define the BCC recipient (hidden)
        string bccEmail = "secret_recipient@example.com";
        MailAddress bccAddress = new MailAddress(bccEmail);

        // 3. Define an optional CC recipient
        string ccEmail = "manager@example.com";
        MailAddress ccAddress = new MailAddress(ccEmail);

        // 4. Create the MailMessage object
        using (MailMessage mail = new MailMessage(toAddress, bccAddress, ccAddress))
        {
            mail.From = toAddress; // Sender address
            mail.Subject = "Test Email with BCC";
            mail.Body = "This is the main content of the email.";

            // Note: When using the constructor that accepts multiple MailAddress objects
            // (as shown above), the BCC relationship is established automatically 
            // if you pass it to the constructor. If building iteratively, ensure 
            // you set the Bcc property explicitly if needed for complex scenarios.

            // In many direct SMTP implementations, setting the To, CC, and Bcc properties 
            // directly on the MailMessage object is the most explicit way:
            mail.Bcc.Add(bccAddress); // Explicitly adding to the BCC collection
            
            // If you were building from scratch, you would ensure mail.To, mail.CC, and mail.Bcc 
            // collections are populated correctly before sending via SmtpClient.

            Console.WriteLine("MailMessage constructed successfully.");
        }
    }
}

Best Practice: Explicitly Managing Collections

While the example above shows a conceptual approach, when working with SmtpClient, it is often cleaner and safer to explicitly manage the collections for To, CC, and BCC before passing the message object to the client. This ensures that the headers are correctly formatted according to RFC standards. Remember that robust application design principles, similar to those emphasized in frameworks like Laravel, stress the importance of clear data flow—and email headers are a critical part of that flow.

Sending via SmtpClient

Once you have constructed your MailMessage, sending it through the SmtpClient is done by connecting to the SMTP server and using the Send() method. The structure of the message object dictates how the receiving mail server interprets those headers.

// Continuation of the example...

using (SmtpClient smtpClient = new SmtpClient("smtp.yourserver.com", 587))
{
    try
    {
        smtpClient.Send(mail);
        Console.WriteLine("Email sent successfully!");
    }
    catch (SmtpException ex)
    {
        Console.WriteLine($"Error sending email: {ex.StatusCode}");
    }
}

Conclusion

Adding BCC to an email in .NET is not complex, but it demands attention to detail regarding the MailMessage object's properties. By correctly populating the To, CC, and crucially, the Bcc collection with valid MailAddress objects before invoking the SMTP client, you ensure that your emails maintain privacy while achieving effective mass communication. Always test your delivery across various email providers to confirm header interpretation, ensuring a reliable experience for all your users.

Note: Blog content is currently available in English.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.