A set of libraries for sending messages across multiple channels.
Current focus:
- Email (
Cross.Messaging.Email.*) - SMS (
Cross.Messaging.Sms.*) - Telegram (
Cross.Messaging.Telegram.*) - Viber (
Cross.Messaging.Viber.*) - WatsApp (
Cross.Messaging.WatsApp.*)
Supported targets: .NET Standard 2.1, .NET 6, .NET 7, .NET 8, .NET 9, .NET 10
Install the Cross.Messaging NuGet package into your .NET project:
Install-Package Cross.Messagingor
dotnet add package Cross.Messagingservices.AddEmailSender(configuration);AddEmailSender:
- binds the
MessagingEmailconfiguration section toMessagingEmailOptions - registers
IEmailSenderService->EmailSenderService(scoped)
IEmailSenderService currently exposes:
SendAsync(toName, toEmail, subject, body, cancellationToken)SendAsync(toName, toEmail, subject, body, priority, cancellationToken)SendAsync(toName, toEmail, subject, textBody, htmlBody, cancellationToken)SendAsync(toName, toEmail, subject, textBody, htmlBody, priority, cancellationToken)SendAsync(toName, toEmail, subject, textBody, htmlBody, attachments, cancellationToken)SendAsync(toName, toEmail, subject, textBody, htmlBody, priority, attachments, cancellationToken)SendAsyncWithContentIds(toName, toEmail, subject, textBody, htmlBody, attachments, contentIdMap, cancellationToken)SendAsyncWithContentIds(toName, toEmail, subject, textBody, htmlBody, priority, attachments, contentIdMap, cancellationToken)
If you use attachment overloads, pass IReadOnlyCollection<IFormFile>? (Microsoft.AspNetCore.Http).
Example:
await emailSender.SendAsync(
toName: "User",
toEmail: "[email protected]",
subject: "Hello",
textBody: "Plain text body",
htmlBody: "<p>HTML body</p>",
priority: XMessagePriority.Normal,
attachments: null,
cancellationToken: cancellationToken);{
"MessagingEmail": {
"SmtpHost": "smtp.example.com",
"SmtpPort": 587,
"UseSsl": true,
"SecureSocket": "StartTls",
"CheckCertificateRevocation": true,
"SmtpLogin": "login",
"SmtpPassword": "password",
"FromUserName": "App Messaging",
"FromUserAddress": "[email protected]",
"RecipientOverride": "",
"BccRecipients": [
{
"Name": "Audit Bot",
"Email": "[email protected]"
}
]
}
}CheckCertificateRevocation applies to MailKit send flows (text+HTML / attachments). Default is true. Set to false only when CRL/OCSP checks fail in constrained networks (for example local/VPN).
BccRecipients is optional; when configured, each entry is added to outgoing messages as BCC.
Entries with empty Email are ignored.
services.AddSmsSender(configuration);AddSmsSender:
- binds the
MessagingSmsconfiguration section toMessagingSmsOptions - registers
ISmsSenderService->SmsSenderService(scoped) - registers an SMS provider only when it is referenced by
DefaultProviderorCountryProvidersand also has settings underMessagingSms:Providers(evaluated at startup; restart if a reload references a provider that was not registered then)
ISmsSenderService.SendAsync(destination, body, cancellationToken) expects destination in E.164 (+...). The country is resolved from the calling code (longest-prefix match); NANP +1 maps to US.
DefaultProvider is used for all destinations unless the resolved country has an override in CountryProviders (list only exceptions there, not every country).
{
"MessagingSms": {
"DefaultProvider": "Telnyx",
"CountryProviders": {
"RO": "SMSClub"
},
"Providers": {
"Telnyx": {
"ApiKey": "KEY",
"From": "+15551234567",
"MessagingProfileId": ""
},
"SMSClub": {
"ApiKey": "TOKEN",
"From": "MySender"
}
}
}
}MessagingProfileId is optional and used for Telnyx modes that require a messaging profile (for example number pool / alphanumeric sender).
For SMSClub, ApiKey is the Bearer token and From is the alphanumeric sender name (src_addr).
Tests use the Given_When_Then naming style:
- Given — context and preconditions.
- When — the action under test.
- Then — the expected outcome.
Example: Given_ValidSmtpOptions_When_SendAsync_Then_UsesConfiguredHost.
Tests live in Cross.Messaging.Tests/ (for example Email/, Sms/).
Available NUnit categories:
UnitIntegration
Run only unit tests (NUnit Category=Unit):
dotnet test Cross.Messaging.Tests/Cross.Messaging.Tests.csproj --filter "Category=Unit"Run only integration tests (NUnit Category=Integration):
dotnet test Cross.Messaging.Tests/Cross.Messaging.Tests.csproj --filter "Category=Integration"Run tests with code coverage (opencover):
dotnet test Cross.Messaging.Tests/Cross.Messaging.Tests.csproj \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover