1. Products
  2.   Email
  3.   Swift
  4.   Swift-SMTP

Email Swift Library for Sending & Tracking Emails

Open Source Swift Email Library for Sending Emails with Local File, HTML & Raw Data Attachments. Add custom Headers, Cc/Bcc & Send Multiple Emails via Swift API.

In today's digital age, email has become an integral part of our lives, both personally and professionally. Sending emails programmatically is a common requirement in various applications, such as notifications, user verification, and communication automation. For developers working with the Swift programming language, the Swift-SMTP library proves to be a valuable tool. It is designed with simplicity in mind. Its user-friendly API makes it easy for software developers to create and send emails with just a few lines of code, making it accessible to users of all skill levels.

Swift-SMTP is an open-source Swift library that provides software developers with a simple and straightforward way to send email messages using the Simple Mail Transfer Protocol (SMTP). The library offers a high-level abstraction over the SMTP protocol, which makes it easy for software developers to integrate email functionality into their Swift applications without dealing with the complexities of the underlying protocol. The library provides various customization options, enabling users to tailor the email appearance, such as setting the sender and recipient details, subject, body, and more.

Swift-SMTP takes security seriously and provides supports secure communication using SSL/TLS encryption, ensuring that sensitive email data remains protected during transmission. Its elegant API, attachment support, customization options, and security features make it a must-have tool for software developers seeking to streamline their email integration process. As you embark on your next Swift project, consider Swift-SMTP as your go-to library for effortless email communication.

Previous Next

Getting Started with Swift-SMTP

The recommended way to install Swift-SMTP is via CocoaPods, please use the following command for easy installation.

Install Swift-SMTP via CocoaPods

 // Add the following to your Podfile
pod 'SwiftSMTP', :git => 'git clone https://github.com/Kitura/Swift-SMTP.git'

Install Swift-SMTP via GitHub

$ git clone https://github.com/Kitura/Swift-SMTP.git

You can also download it directly from GitHub.

Create & Send Email via Swift API

The open source Swift-SMTP API has included complete support for composing and sending email messages with just a couple of lines of code inside Swift applications. The API is very easy to use and shields software developers from the intricate details of SMTP communication. There are several important features part of the library for handling email messages, such as add attachments to email, Add CC and BCC, sending multiple mails support, and many more. The following example demonstrates how simply software developers can send email message to different users via Swift code.

How to Send Email Message via Swift API?

import SwiftSMTP

let smtp = SMTP(
    hostname: "smtp.example.com",
    email: "your_email@example.com",
    password: "your_email_password"

let message = Message(
    from: "your_email@example.com",
    to: "recipient@example.com",
    subject: "Hello from Swift-SMTP!",
    body: "This is a test email sent using Swift-SMTP."

do {
    try smtp.send(message: message)
    print("Email sent successfully!")
} catch {
    print("Failed to send the email: \(error)")

Add & Manage Attachment via Swift API

Sending attachments with email messages is a common requirement, especially in applications that deal with file sharing. The open source Swift-SMTP library enables software developers to send email messages with attachments. The library allows to attach files like images, documents, or even multimedia to your emails effortlessly. The following example shows how software developers can attach different types of files to the email message inside Swift applications.

How to Attach Various Types of Files to Email Messages inside Swift Apps?

// Create a file `Attachment`
let fileAttachment = Attachment(
    filePath: "~/img.png",          
    // "CONTENT-ID" lets you reference this in another attachment
    additionalHeaders: ["CONTENT-ID": "img001"]

// Create an HTML `Attachment`
let htmlAttachment = Attachment(
    htmlContent: "Here's an image: ",
    // To reference `fileAttachment`
    related: [fileAttachment]

// Create a data `Attachment`
let data = "{\"key\": \"hello world\"}".data(using: .utf8)!
let dataAttachment = Attachment(
    data: data,
    mime: "application/json",
    name: "file.json",
    // send as a standalone attachment
    inline: false   

// Create a `Mail` and include the `Attachment`s
let mail = Mail(
    from: from,
    to: [to],
    subject: "Check out this image and JSON file!",
    // The attachments we created earlier
    attachments: [htmlAttachment, dataAttachment]

// Send the mail

Customization & Security Support via Swift

The open source Swift-SMTP library provides various customization options, enabling software developers to tailor the email appearance, such as setting the sender and recipient details, subject, body, and more. Moreover, the library takes security very seriously and incorporates security features like TLS encryption, ensuring that email communications are protected from potential eavesdropping and tampering.