A .NET Core service for sending bulk emails through Office 365 with rate limiting and tracking capabilities. Built using Clean Architecture principles.
- Office 365 SMTP integration
- Daily email rate limiting (configurable, default 3600/day)
- Email tracking to prevent duplicate sends
- CSV-based recipient management
- HTML email template support with personalization
- Swagger API documentation
- Clean Architecture implementation
- Entity Framework Core for data persistence
- .NET 7.0 SDK
- SQL Server (or LocalDB)
- Office 365 account with SMTP access
- Visual Studio 2022 or VS Code
MailingService/
├── src/
│ ├── MailingService.Domain/ # Enterprise business rules
│ ├── MailingService.Application/ # Application business rules
│ ├── MailingService.Infrastructure/# Data and external concerns
│ └── MailingService.Api/ # API endpoints and configuration
- Update
appsettings.jsonwith your settings:
{
"ConnectionStrings": {
"DefaultConnection": "Your-DB-Connection-String"
},
"MailSettings": {
"Office365Username": "your-email@yourdomain.com",
"Office365Password": "your-password",
"FromEmail": "your-email@yourdomain.com",
"FromName": "Your Name",
"HtmlTemplatePath": "Templates/email-template.html",
"CsvFilePath": "Data/recipients.csv",
"DailyEmailLimit": 3600
}
}- Create required directories and files:
Templates/email-template.html- Your email templateData/recipients.csv- CSV file with recipients (format: Email,Name)
- Clone the repository:
git clone https://github.com/yourusername/MailingService.git- Navigate to the project directory:
cd MailingService- Restore dependencies:
dotnet restore- Update the database:
dotnet ef database update- Run the application:
dotnet run --project src/MailingService.ApiPOST /api/email/send-batchReads recipients from CSV file and sends personalized emails.
GET /api/email/daily-countReturns current daily email statistics.
The recipients CSV file should follow this format:
Email,Name
recipient1@example.com,John Doe
recipient2@example.com,Jane SmithThe HTML template supports personalization using placeholders:
<html>
<body>
<h1>Hello {{Name}}</h1>
<p>Your email content here.</p>
</body>
</html>- Follow Clean Architecture principles
- Use Entity Framework Core migrations for database changes
- Keep services stateless
- Handle exceptions appropriately
- Use async/await for I/O operations
- Store sensitive data (passwords, connection strings) in user secrets during development
- Use appropriate authentication/authorization in production
- Implement rate limiting per client if needed
- Monitor for abuse
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.