All Projects → PerfectlySoft → Perfect-SMTP

PerfectlySoft / Perfect-SMTP

Licence: Apache-2.0 license
SMTP Client for Perfect.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Perfect-SMTP

smtp-client
SMTP Client Library in C
Stars: ✭ 68 (+257.89%)
Mutual labels:  smtp, smtp-library, smtpclient
Perfect-HTTPServer
HTTP server for Perfect.
Stars: ✭ 104 (+447.37%)
Mutual labels:  perfect, server-side-swift
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (-10.53%)
Mutual labels:  perfect, server-side-swift
Perfect-HTTP
Base HTTP Support for Perfect.
Stars: ✭ 29 (+52.63%)
Mutual labels:  perfect, server-side-swift
smtpd
SMTP server (library) for receiving emails, written in pure PHP.
Stars: ✭ 94 (+394.74%)
Mutual labels:  smtp, smtp-library
Perfect-URLRouting
Perfect Example Module: URL Routing
Stars: ✭ 20 (+5.26%)
Mutual labels:  perfect, server-side-swift
SwiftString
A comprehensive, lightweight string extension for Swift 3.x & 4.0
Stars: ✭ 117 (+515.79%)
Mutual labels:  perfect, server-side-swift
Perfect-XML
XML support for Perfect.
Stars: ✭ 16 (-15.79%)
Mutual labels:  perfect, server-side-swift
Perfect-JSON-API
An Example JSON API for Perfect
Stars: ✭ 43 (+126.32%)
Mutual labels:  perfect, server-side-swift
Perfect
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
Stars: ✭ 13,890 (+73005.26%)
Mutual labels:  perfect, server-side-swift
Perfect-URL-Shortener
An Example URL Shortener System for Perfect
Stars: ✭ 37 (+94.74%)
Mutual labels:  perfect, server-side-swift
Perfect-WebSocketsServer
Perfect Example Module: WebSockets Server
Stars: ✭ 34 (+78.95%)
Mutual labels:  perfect, server-side-swift
Perfect-Zip
Perfect Zip compression utility.
Stars: ✭ 20 (+5.26%)
Mutual labels:  perfect, server-side-swift
Perfect-Authentication
OAuth2 Implementations with Facebook, Google, LinkedIn, Slack, SalesForce and GitHub providers.
Stars: ✭ 14 (-26.32%)
Mutual labels:  perfect, server-side-swift
enough mail
IMAP, POP3 and SMTP clients for Dart developers. Contains both low level as well as a high level API.
Stars: ✭ 78 (+310.53%)
Mutual labels:  smtp, smtp-library
Perfect-Weather
Demonstrate using URL Routes & variables, Fetching of remote data from API's as JSON, reading and transforming to data more appropriately consumable by an API client.
Stars: ✭ 32 (+68.42%)
Mutual labels:  perfect, server-side-swift
Mail
The Hoa\Mail library.
Stars: ✭ 24 (+26.32%)
Mutual labels:  smtp
Meteor-Mailer
📮 Bulletproof email queue on top of NodeMailer with support of multiple clusters and servers setup
Stars: ✭ 21 (+10.53%)
Mutual labels:  smtp
emailqueue
A fast, simple yet very efficient email queuing system for PHP/MySQL
Stars: ✭ 75 (+294.74%)
Mutual labels:  smtp
strudelpy
Easy going emails with Python for easy going people, who email
Stars: ✭ 14 (-26.32%)
Mutual labels:  smtp

Perfect - SMTP 简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.1 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project provides an SMTP library.

This package builds with Swift Package Manager and is part of the Perfect project.

Ensure you have installed and activated the latest Swift 4.1.1 tool chain.

Linux Build Note

Please make sure libssl-dev was installed on Ubuntu 16.04:

$ sudo apt-get install libssl-dev

The Best Practice

Prior to code with Perfect-SMTP, please feel free to try SMTP command line example by curl.

This command line tool can be helpful to understand the SMTP protocol and the objective server you are going to work with.

Quick Start

To use SMTP class, please modify the Package.swift file and add following dependency:

.package(url: "https://github.com/PerfectlySoft/Perfect-SMTP.git", from: "3.0.0")

Then please import SMTP library into the swift source code:

import PerfectSMTP

Data Structures

Perfect SMTP contains three different data structures: SMTPClient, Recipient and EMail.

SMTPClient

SMTPClient object is a data structure to store mail server login information:

let client = SMTPClient(url: "smtp://mailserver.address", username: "[email protected]", password:"secret")

Recipient

Recipient object is a data structure which store one's name and email address:

let recipient = Recipient(name: "Someone's Full Name", address: "[email protected]")

EMail

Using email object to compose and send an email. Check the following example code:

// initialize an email draft with mail connection / login info
var email = EMail(client: client)

// set the title of email
email.subject = "Mail Title"

// set the sender info
email.from = Recipient(name: "My Full Name", address: "[email protected]")

// fill in the main content of email, plain text or html
email.html = "<h1>Hello, world!</h1><hr><img src='http://www.perfect.org/images/perfect-logo-2-0.svg'>"

// set the mail recipients, to / cc / bcc are all arrays
email.to.append(Recipient(name: "First Receiver", address: "[email protected]"))
email.cc.append(Recipient(name: "Second Receiver", address: "[email protected]"))
email.bcc.append(Recipient(name: "An invisible receiver", address: "[email protected]"))

// add attachments
email.attachments.append("/path/to/file.txt")
email.attachments.append("/path/to/img.jpg")

// send the email and call back if done.
do {
  try email.send { code, header, body in
    /// response info from mail server
    print(code)
    print(header)
    print(body)
  }//end send
}catch(let err) {
  /// something wrong
}

Members of EMail Object

  • client: SMTPClient, login info for mail server connection
  • to: [Recipient], array of mail recipients
  • cc: [Recipient], array of mail recipients, "copy / forward"
  • bcc:[Recipient], array of mail recipients, will not appear in the to / cc mail.
  • from: Recipient, email address of the current sender
  • subject: String, title of the email
  • attachments: [String], full path of attachments, i.e., ["/path/to/file1.txt", "/path/to/file2.gif" ...]
  • content: String, mail body in text, plain text or html
  • html: String, alias of content (share the same variable as content)
  • text: String, set the content to plain text
  • send(completion: @escaping ((Int, String, String)->Void)), function of sending email with callback. The completion callback has three parameters, please check Perfect-CURL performFully() for more information:
    • code: Int, mail server response code. Zero for OK.
    • header: String, mail server response header string.
    • body: String, mail server response body string.

Example

A demo can be found here: Perfect SMTP Demo

Tips for SMTPS

We've received a lot of requests about google smtp examples, Thanks for @ucotta @james and of course the official Perfect support from @iamjono, this note might be helpful for building gmail applications: ⚠️*the SMTPClient url needs to be smtps://smtp.gmail.com, and you may need to “turn on access for less secure apps” in the google settings.*⚠️

Please check the SMTPS code below, note the only difference is the URL pattern:

import PerfectSMTP

let client = SMTPClient(url: "smtps://smtp.gmail.com", username: "[email protected]", password:"yourpassword")

var email = EMail(client: client)

email.subject = "a topic"
email.content = "a message"

email.cc.append(Recipient(address: "[email protected]"))

do {
  try email.send { code, header, body in
    /// response info from mail server
    print(code)
  }//end send
}catch(let err) {
  /// something wrong
}

Further Information

For more information on the Perfect project, please visit perfect.org.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].