Table of Contents

MailDistributor Class

Definition

Namespace
Cuemon.Net.Mail
Assemblies
Cuemon.Net.dll
Source
src/Cuemon.Net/Mail/MailDistributor.cs

Provides a way for applications to distribute one or more e-mails in batches by using the Simple Mail Transfer Protocol (SMTP).

public class MailDistributor
Inheritance
object
MailDistributor

Examples

The following example demonstrates how to construct a and skip delivery through a filter when you only want to validate a message batch.

using System;
using System.Net.Mail;
using System.Threading.Tasks;
using Cuemon.Net.Mail;

namespace MyApp.Examples;

public static class MailDistributorExample
{
    public static async Task DemonstrateAsync()
    {
        var distributor = new MailDistributor(() => new SmtpClient("smtp.example.com", 25), deliverySize: 10);
        using var mail = new MailMessage("sender@example.com", "receiver@example.com")
        {
            Subject = "Docs sample",
            Body = "This message is filtered out before delivery."
        };

        await distributor.SendOneAsync(mail, _ => false);

        Console.WriteLine("Delivery skipped by filter.");
    }
}

Constructors

Name Description
MailDistributor(Func<SmtpClient>, int)

Initializes a new instance of the MailDistributor class.

Methods

Name Description
SendAsync(IEnumerable<MailMessage>, Func<MailMessage, bool>)

Sends the specified sequence of mails to an SMTP server.

SendOneAsync(MailMessage, Func<MailMessage, bool>)

Sends the specified mail to an SMTP server.