1. Products
  2.   Email
  3.   Swift
  4.   Hedwig
 
  

Open Source Swift  Library for Email Management 

Free Swift API that allows developers to send messages with attachments, sending messages to multiple users, mail validation and customization, mail header support, and so on.

The Hedwig Swift library gives software developers the ability to create and send email messages to any SMTP server inside their own swift applications. The library is very easy to use and can be used on multiple platforms. The library is open source and released under the MIT license. The library can be easily connected to all SMTP servers, using either plain, SSL, or TLS ports.

The Hedwig is pure Swift implementation and has provided several important features related to email message handling such as creating emails, email authentication support, sending email messages with HTML body, adding attachments to emails, sending emails to multiple users, inline image support, read email messages, email validation, and customization, mail header support, queued mail sending, send mails concurrently and so on. The library is very stable and enables users to handle email messages more efficiently.

Previous Next

Getting Started with Hedwig

The easiest way to install the Hedwig library is via GitHub. Please install it using the following command for easy installation.

Install Hedwig via GitHub

 go get https://github.com/onevcat/Hedwig.git

Email Creation & Sending via Swift Library

The open source Hedwig library enables software programmers to compose and send email messages inside their Swift applications. You need to provide a message title as well message body. The library has provided support for sending text as well as HTML-based email messages. You can also send an email message to multiple users using CC and BC options. Once all the required information is provided the email message will be directed to all the provided recipients.Here is an example that shows how software developers can create and send HTML email message using Swift library.

How to Send HTML Email Messages via Swift Library?

let hedwig = Hedwig(hostName: "smtp.example.com", user: "foo@bar.com", password: "password")
let attachment = Attachment(htmlContent: "

Title

Content

") let mail = Mail( text: "Fallback text", from: "onev@onevcat.com", to: "foo@bar.com", subject: "Title", attachments: [attachment] ) hedwig.send(mail) { error in if error != nil { /* Error happened */ } }

Send Emails with Attachments via Swift Library

The Hedwig library has provided complete functionality for sending email messages with attachments using Swift commands. The library has provided several ways to add attachments to your email messages, such as creating an attachment from a local file path, embedding image attachments in HTML, and creating attachments from raw data. You can also access and read attachments with just a couple of lines of code. Here is an example that shows how software developers can add attachments to their email messages and send it inside Swift Apps.

How to Add Attachments to Email Messages inside Swift Applications?

let imagePath = "/tmp/image.png"
// You can create an attachment from a local file path.
let imageAttachment = Attachment(
        filePath: imagePath, 
        inline: true, 
        // Add "Content-ID" if you need to embed this image to another attachment.
        additionalHeaders: ["Content-ID": "hedwig-image"] 
)
let html = Attachment(
        htmlContent: "A photo ", 
        // If imageAttachment only used embeded in HTML, I recommend to set it as related.
        related: [imageAttachment]
)

// You can also create attachment from raw data.
let data = "{\"key\": \"hello world\"}".data(using: .utf8)!
let json = Attachment(
        data: data, 
        mime: "application/json", 
        name: "file.json", 
        inline: false // Send as standalone attachment.
)

Read Existing Email Message

The open source Hedwig library allows developers to programmatically access and read email messages inside their own Swift apps. You can access emails using SMTP settings (security layer, authentication method, etc.). You can use multiple methods to access incoming emails such as the most recent emails, emails sorted by name or date, view messages in ascending or descending order, and so on. The following example demonstrates how to software developers can access and read existing email messages inside their own Swift applications.

How to Read Existing Email Messages using Swift API?

let hedwig = Hedwig(hostName: "smtp.example.com", user: "foo@bar.com", password: "password")
let mail = Mail(
    text: "Hello World!",
    from: "sender@example.com",
    to: "recipient@example.com",
    subject: "Greetings"
)
hedwig.send(mail) { error in
    if let error = error {
        print("Error sending email: \(error)")
    } else {
        print("Email sent successfully!")
    }
}

Use Custom Email Headers

The free email Hedwig enables programmers to add custom headers to their email messages inside their own Swift applications with ease. It encompasses very useful information related to the email transmission process and helps users to track their email messages with ease.  The Hedwig library allows you to manage your custom headers with ease.

 English