EmfMailService 1.0.7

dotnet add package EmfMailService --version 1.0.7
                    
NuGet\Install-Package EmfMailService -Version 1.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EmfMailService" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EmfMailService" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="EmfMailService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EmfMailService --version 1.0.7
                    
#r "nuget: EmfMailService, 1.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EmfMailService@1.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EmfMailService&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=EmfMailService&version=1.0.7
                    
Install as a Cake Tool

EmfMailService

NuGet License: MIT

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 — IFormFile ile
  • ✅ 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: MaxFileSize değ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 = trueSslOnConnect (Port 465)
UseSSL = falseStartTls (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: MaxFileSize is 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 = trueSslOnConnect (Port 465)
UseSSL = falseStartTls (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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 74 4/20/2026
1.0.6 112 3/16/2026
1.0.5 185 7/27/2025
1.0.4 213 1/30/2025
1.0.3 198 9/9/2024
1.0.2 207 7/6/2024
1.0.1 173 7/6/2024
1.0.0 200 7/6/2024

Ek dosya desteği ve dosya boyutu kontrolü ile e-posta gönderme desteği içeren ilk sürüm.