EmfMailService 1.0.7
dotnet add package EmfMailService --version 1.0.7
NuGet\Install-Package EmfMailService -Version 1.0.7
<PackageReference Include="EmfMailService" Version="1.0.7" />
<PackageVersion Include="EmfMailService" Version="1.0.7" />
<PackageReference Include="EmfMailService" />
paket add EmfMailService --version 1.0.7
#r "nuget: EmfMailService, 1.0.7"
#:package EmfMailService@1.0.7
#addin nuget:?package=EmfMailService&version=1.0.7
#tool nuget:?package=EmfMailService&version=1.0.7
EmfMailService
Author / Yazar: Mehmet SEYİTOĞLU
Company / Şirket: EMF BİLGİSAYAR YAZILIM YÖNETİM VE DANIŞMANLIK HİZMETLERİ
Target Framework: .NET 10
License / Lisans: MIT
🇹🇷 Türkçe Dokümantasyon
Genel Bakış
EmfMailService, .NET Core uygulamaları için SMTP üzerinden e-posta gönderme, dosya eki (attachment) desteği ve dosya boyutu kontrolü sunan hafif bir e-posta servis kütüphanesidir. Altyapıda MailKit ve MimeKit kütüphanelerini kullanır.
Ne İşe Yarar?
- ✅ SMTP üzerinden e-posta gönderme
- ✅ Dosya eki (attachment) desteği —
IFormFileile - ✅ Dosya boyutu limiti kontrolü
- ✅ SSL/TLS güvenli bağlantı desteği
- ✅ Asenkron e-posta gönderimi
- ✅ Yapılandırılabilir SMTP ayarları (
appsettings.json) - ✅ Dependency Injection desteği
Kurulum
dotnet add package EmfMailService
appsettings.json Konfigürasyonu
{
"SmtpSettings": {
"Server": "smtp.gmail.com",
"Port": 465,
"SenderName": "Uygulama Adı",
"SenderEmail": "noreply@example.com",
"Username": "noreply@example.com",
"Password": "uygulama-sifresi",
"MaxFileSize": 10485760,
"UseSSL": true
}
}
Not:
MaxFileSizedeğeri byte cinsindendir.10485760= 10 MB.
DI Kaydı (Dependency Injection)
// Program.cs
// SmtpSettings'i appsettings.json'dan oku ve DI'a kaydet
var smtpSettings = builder.Configuration.GetSection("SmtpSettings").Get<SmtpSettings>();
builder.Services.AddSingleton(smtpSettings);
builder.Services.AddScoped<IEmailService, EmailService>();
Temel Kullanım Örnekleri
Basit E-posta Gönderimi
public class NotificationService
{
private readonly IEmailService _emailService;
public NotificationService(IEmailService emailService)
{
_emailService = emailService;
}
// Basit metin e-posta gönder
public async Task SendWelcomeEmailAsync(string userEmail)
{
await _emailService.SendEmailAsync(
toEmail: userEmail,
subject: "Hoş Geldiniz!",
body: "Uygulamamıza hoş geldiniz. Hesabınız başarıyla oluşturuldu."
);
}
}
Dosya Ekli E-posta Gönderimi
// API Controller'da dosya ekli e-posta
[HttpPost("send-with-attachment")]
public async Task<IActionResult> SendEmailWithAttachment(
[FromForm] string toEmail,
[FromForm] string subject,
[FromForm] string body,
[FromForm] List<IFormFile> attachments)
{
try
{
await _emailService.SendEmailAsync(toEmail, subject, body, attachments);
return Ok(new { Message = "E-posta başarıyla gönderildi." });
}
catch (Exception ex)
{
return BadRequest(new { Error = ex.Message });
}
}
Servis Katmanında Kullanım
public class InvoiceService
{
private readonly IEmailService _emailService;
public InvoiceService(IEmailService emailService)
{
_emailService = emailService;
}
public async Task SendInvoiceEmailAsync(string customerEmail, List<IFormFile> invoiceFiles)
{
try
{
await _emailService.SendEmailAsync(
toEmail: customerEmail,
subject: "Faturanız",
body: "Faturanız ekte gönderilmektedir.",
attachments: invoiceFiles
);
}
catch (Exception ex)
{
// Dosya boyutu limiti aşıldığında hata fırlatılır
// "Dosya boyutu X MB limitini aşıyor."
throw;
}
}
}
SMTP Ayarları
| Property | Açıklama | Örnek |
|---|---|---|
Server |
SMTP sunucu adresi | smtp.gmail.com |
Port |
SMTP port numarası | 465 (SSL), 587 (TLS) |
SenderName |
Gönderen adı | Uygulama Adı |
SenderEmail |
Gönderen e-posta adresi | noreply@example.com |
Username |
SMTP kimlik doğrulama kullanıcı adı | noreply@example.com |
Password |
SMTP kimlik doğrulama şifresi | uygulama-sifresi |
MaxFileSize |
Maksimum dosya boyutu (byte) | 10485760 (10 MB) |
UseSSL |
SSL bağlantısı kullan | true / false |
UseSSL = true→SslOnConnect(Port 465)
UseSSL = false→StartTls(Port 587)
🇬🇧 English Documentation
Overview
EmfMailService is a lightweight email service library for .NET Core applications that provides SMTP-based email sending, file attachment support, and file size validation. It uses MailKit and MimeKit under the hood.
What Does It Do?
- ✅ Send emails via SMTP
- ✅ File attachment support — with
IFormFile - ✅ File size limit validation
- ✅ SSL/TLS secure connection support
- ✅ Asynchronous email sending
- ✅ Configurable SMTP settings via
appsettings.json - ✅ Dependency Injection support
Installation
dotnet add package EmfMailService
appsettings.json Configuration
{
"SmtpSettings": {
"Server": "smtp.gmail.com",
"Port": 465,
"SenderName": "Application Name",
"SenderEmail": "noreply@example.com",
"Username": "noreply@example.com",
"Password": "app-password",
"MaxFileSize": 10485760,
"UseSSL": true
}
}
Note:
MaxFileSizeis in bytes.10485760= 10 MB.
DI Registration (Dependency Injection)
// Program.cs
// Read SmtpSettings from appsettings.json and register to DI
var smtpSettings = builder.Configuration.GetSection("SmtpSettings").Get<SmtpSettings>();
builder.Services.AddSingleton(smtpSettings);
builder.Services.AddScoped<IEmailService, EmailService>();
Basic Usage Examples
Simple Email Sending
public class NotificationService
{
private readonly IEmailService _emailService;
public NotificationService(IEmailService emailService)
{
_emailService = emailService;
}
// Send a simple text email
public async Task SendWelcomeEmailAsync(string userEmail)
{
await _emailService.SendEmailAsync(
toEmail: userEmail,
subject: "Welcome!",
body: "Welcome to our application. Your account has been created successfully."
);
}
}
Send Email with Attachments
// API Controller with file attachments
[HttpPost("send-with-attachment")]
public async Task<IActionResult> SendEmailWithAttachment(
[FromForm] string toEmail,
[FromForm] string subject,
[FromForm] string body,
[FromForm] List<IFormFile> attachments)
{
try
{
await _emailService.SendEmailAsync(toEmail, subject, body, attachments);
return Ok(new { Message = "Email sent successfully." });
}
catch (Exception ex)
{
return BadRequest(new { Error = ex.Message });
}
}
Service Layer Usage
public class InvoiceService
{
private readonly IEmailService _emailService;
public InvoiceService(IEmailService emailService)
{
_emailService = emailService;
}
public async Task SendInvoiceEmailAsync(string customerEmail, List<IFormFile> invoiceFiles)
{
try
{
await _emailService.SendEmailAsync(
toEmail: customerEmail,
subject: "Your Invoice",
body: "Please find your invoice attached.",
attachments: invoiceFiles
);
}
catch (Exception ex)
{
// Throws when file size limit is exceeded
// "Dosya boyutu X MB limitini aşıyor."
throw;
}
}
}
SMTP Settings
| Property | Description | Example |
|---|---|---|
Server |
SMTP server address | smtp.gmail.com |
Port |
SMTP port number | 465 (SSL), 587 (TLS) |
SenderName |
Display name of the sender | Application Name |
SenderEmail |
Sender email address | noreply@example.com |
Username |
SMTP authentication username | noreply@example.com |
Password |
SMTP authentication password | app-password |
MaxFileSize |
Maximum file size in bytes | 10485760 (10 MB) |
UseSSL |
Use SSL connection | true / false |
UseSSL = true→SslOnConnect(Port 465)
UseSSL = false→StartTls(Port 587)
API Reference / API Referansı
| Interface / Class | Description (EN) | Açıklama (TR) |
|---|---|---|
IEmailService |
Email service abstraction | E-posta servis soyutlaması |
EmailService |
SMTP email service implementation | SMTP e-posta servis implementasyonu |
SmtpSettings |
SMTP configuration model | SMTP yapılandırma modeli |
Dependencies / Bağımlılıklar
MailKit(4.15.1)MimeKit(4.15.1)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Ek dosya desteği ve dosya boyutu kontrolü ile e-posta gönderme desteği içeren ilk sürüm.