### Creating a Mail.User
Source: https://github.com/kitura/swift-smtp/blob/master/migration-guide.md
Example of how to create a User struct, now nested within the Mail struct.
```swift
let sender = Mail.User(name: "Sloth", email: "sloth@gmail.com")
```
--------------------------------
### Swift Package Manager Installation
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/index.html
Example of how to add SwiftSMTP as a dependency in your Package.swift file.
```swift
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "MyProject",
products: [
.library(
name: "MyProject",
targets: ["MyProject"]),
],
dependencies: [
.package(url: "https://github.com/Kitura/Swift-SMTP", .upToNextMinor(from: "5.1.0")), // add the dependency
],
targets: [
.target(
name: "MyProject",
dependencies: ["SwiftSMTP"]),
.testTarget(
name: "MyProjectTests",
dependencies: ["MyProject"]),
]
)
```
--------------------------------
### Swift Package Manager Installation
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Example of how to add Swift-SMTP to your project's Package.swift file.
```swift
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "MyProject",
products: [
.library(
name: "MyProject",
targets: ["MyProject"])
],
dependencies: [
.package(url: "https://github.com/Kitura/Swift-SMTP", .upToNextMinor(from: "5.1.0")), // add the dependency
],
targets: [
.target(
name: "MyProject",
dependencies: ["SwiftSMTP"]),
.testTarget(
name: "MyProjectTests",
dependencies: ["MyProject"])
]
)
```
--------------------------------
### SMTP initialization with access token for XOAUTH2
Source: https://github.com/kitura/swift-smtp/blob/master/migration-guide.md
Example of initializing the SMTP struct when using XOAUTH2 authorization, passing the access token in the password parameter.
```swift
let smtp = SMTP(
hostname: "smtp.gmail.com",
email: "example@gmail.com",
password: "accessToken",
authMethods: [.xoauth2]
)
```
--------------------------------
### Send email with basic details
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Example of creating a Mail object and sending it.
```swift
let drLight = Mail.User(name: "Dr. Light", email: "drlight@gmail.com")
let megaman = Mail.User(name: "Megaman", email: "megaman@gmail.com")
let mail = Mail(
from: drLight,
to: [megaman],
subject: "Humans and robots living together in harmony and equality.",
text: "That was my ultimate wish."
)
smtp.send(mail) { (error) in
if let error = error {
print(error)
}
}
```
--------------------------------
### SMTP initializer before 3.0.0
Source: https://github.com/kitura/swift-smtp/blob/master/migration-guide.md
Signature of the SMTP initializer before version 3.0.0.
```swift
public init(hostname: String,
email: String,
password: String,
port: Port = Ports.tls.rawValue,
ssl: SSL? = nil,
authMethods: [AuthMethod] = [],
domainName: String = "localhost",
accessToken: String? = nil,
timeout: UInt = 10)
```
--------------------------------
### SMTP initializer after 3.0.0
Source: https://github.com/kitura/swift-smtp/blob/master/migration-guide.md
Signature of the SMTP initializer after version 3.0.0.
```swift
public init(hostname: String,
email: String,
password: String,
port: Int32 = 465,
useTLS: Bool = true,
tlsConfiguration: TLSConfiguration? = nil,
authMethods: [AuthMethod] = [],
accessToken: String? = nil,
domainName: String = "localhost",
timeout: UInt = 10)
```
--------------------------------
### Add Cc and Bcc
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/index.html
Example of adding Cc and Bcc recipients to an email.
```swift
let roll = Mail.User(name: "Roll", email: "roll@gmail.com")
let zero = Mail.User(name: "Zero", email: "zero@gmail.com")
let mail = Mail(
from: drLight,
to: [megaman],
cc: [roll],
bcc: [zero],
subject: "Robots should be used for the betterment of mankind.",
text: "Any other use would be...unethical."
)
smtp.send(mail)
```
--------------------------------
### Send email with Cc and Bcc
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Example of sending an email with Cc and Bcc recipients.
```swift
let drLight = Mail.User(name: "Dr. Light", email: "drlight@gmail.com")
let megaman = Mail.User(name: "Megaman", email: "megaman@gmail.com")
let roll = Mail.User(name: "Roll", email: "roll@gmail.com")
let zero = Mail.User(name: "Zero", email: "zero@gmail.com")
let mail = Mail(
from: drLight,
to: [megaman],
cc: [roll],
bcc: [zero],
subject: "Robots should be used for the betterment of mankind.",
text: "Any other use would be...unethical."
)
smtp.send(mail)
```
--------------------------------
### TLSMode enum for connection security
Source: https://github.com/kitura/swift-smtp/blob/master/migration-guide.md
The TLSMode enum provides options for configuring connection security in the SMTP struct.
```swift
/// TLSMode enum for what form of connection security to enforce.
public enum TLSMode {
/// Upgrades the connection to TLS if STARTLS command is received, else sends mail without security.
case normal
/// Send mail over plaintext and ignore STARTLS commands and TLS options. Could throw an error if server requires TLS.
case ignoreTLS
/// Only send mail after an initial successful TLS connection. Connection will fail if a TLS connection cannot be established. The default port, 587, will likely need to be adjusted depending on your server.
case requireTLS
/// Expect a STARTTLS command from the server and require the connection is upgraded to TLS. Will throw if the server does not issue a STARTTLS command.
case requireSTARTTLS
}
```
--------------------------------
### Initialize a configuration using a Certificate Chain File.
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/TLSConfiguration.html
Initialize a configuration using a Certificate Chain File.
```Swift
public init(withChainFilePath chainFilePath: String?,
withPassword password: String?,
usingSelfSignedCerts selfSigned: Bool = true,
clientAllowsSelfSignedCertificates: Bool = false,
cipherSuite: String? = nil)
```
--------------------------------
### Initialize a configuration using a CA Certificate file.
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/TLSConfiguration.html
Initialize a configuration using a CA Certificate file.
```Swift
public init(withCACertificateFilePath caCertificateFilePath: String?,
usingCertificateFile certificateFilePath: String?,
withKeyFile keyFilePath: String? = nil,
usingSelfSignedCerts selfSigned: Bool = true,
cipherSuite: String? = nil)
```
--------------------------------
### Initialize a configuration with no backing certificates.
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/TLSConfiguration.html
Initialize a configuration with no backing certificates.
```Swift
public init(withCipherSuite cipherSuite: String? = nil,
clientAllowsSelfSignedCertificates: Bool = false)
```
--------------------------------
### Initialize a configuration using a CA Certificate directory.
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/TLSConfiguration.html
Initialize a configuration using a CA Certificate directory.
```Swift
public init(withCACertificateDirectory caCertificateDirPath: String?,
usingCertificateFile certificateFilePath: String?,
withKeyFile keyFilePath: String? = nil,
usingSelfSignedCerts selfSigned: Bool = true,
cipherSuite: String? = nil)
```
--------------------------------
### Initialize an SMTP instance
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Basic initialization of the SMTP client.
```swift
import SwiftSMTP
let smtp = SMTP(
hostname: "smtp.gmail.com", // SMTP server address
email: "user@gmail.com", // username to login
password: "password" // password to login
)
```
--------------------------------
### Initializer
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Mail/User.html
Initializes a `User`.
```swift
public init(name: String? = nil, email: String)
```
--------------------------------
### Initialize an Attachment from a local file
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Attachment.html
Initializes an Attachment from a local file path.
```Swift
public init(filePath: String,
mime: String = "application/octet-stream",
name: String? = nil,
inline: Bool = false,
additionalHeaders: [String: String] = [:],
relatedAttachments: [Attachment] = [])
```
--------------------------------
### SMTP Initializer
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP.html
Initializes an SMTP instance.
```Swift
public init(hostname: String,
email: String,
password: String,
port: Int32 = 587,
tlsMode: TLSMode = .requireSTARTTLS,
tlsConfiguration: TLSConfiguration? = nil,
authMethods: [AuthMethod] = [],
domainName: String = "localhost",
timeout: UInt = 10)
```
--------------------------------
### Initialize a data Attachment
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Attachment.html
Initializes an Attachment with raw data.
```Swift
public init(data: Data,
mime: String,
name: String,
inline: Bool = false,
additionalHeaders: [String: String] = [:],
relatedAttachments: [Attachment] = [])
```
--------------------------------
### TLSMode.requireSTARTTLS
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP/TLSMode.html
Expect a STARTTLS command from the server and require the connection is upgraded to TLS. Will throw if the server does not issue a STARTTLS command.
```swift
case requireSTARTTLS
```
--------------------------------
### Initialize an HTML Attachment
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Attachment.html
Initializes an Attachment with HTML content.
```Swift
public init(htmlContent: String,
characterSet: String = "utf-8",
alternative: Bool = true,
additionalHeaders: [String: String] = [:],
relatedAttachments: [Attachment] = [])
```
--------------------------------
### login
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/AuthMethod.html
LOGIN authentication.
```swift
case login = "LOGIN"
```
--------------------------------
### Initialize an HTML Attachment
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/Structs/Attachment.html
Initializes an HTML Attachment with HTML content, character set, alternative flag, and optional additional headers and related attachments.
```swift
public init(htmlContent: String,
characterSet: String = "utf-8",
alternative: Bool = true,
additionalHeaders: [String: String] = [:],
relatedAttachments: [Attachment] = [])
```
--------------------------------
### plain
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/AuthMethod.html
PLAIN authentication.
```swift
case plain = "PLAIN"
```
--------------------------------
### Send attachments
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/index.html
Create an Attachment, attach it to your Mail, and send it through the SMTP handle. Demonstrates sending local file, HTML, and raw data attachments.
```swift
// 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
smtp.send(mail)
/* Each type of attachment has additional parameters for further customization */
```
--------------------------------
### TLSConfiguration Initializer
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/TLSConfiguration.html
Initializes a TLSConfiguration with optional certificate chain file, password, self-signed certificate settings, and cipher suite.
```swift
public init(withChainFilePath chainFilePath: String?,
withPassword password: String? = nil,
usingSelfSignedCerts selfSigned: Bool = true,
clientAllowsSelfSignedCertificates: Bool = false,
cipherSuite: String? = nil)
```
--------------------------------
### requiredSTARTTLS Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
STARTTLS was required but the server did not request it.
```swift
case requiredSTARTTLS
```
--------------------------------
### Send attachments
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Demonstrates how to create and send different types of attachments (file, HTML, raw data) with an email.
```swift
// 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
smtp.send(mail)
/* Each type of attachment has additional parameters for further customization */
```
--------------------------------
### send(_:progress:completion:)
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP.html
Sends an array of mails with optional progress and completion callbacks.
```swift
public func send(_ mails: [Mail],
progress: Progress = nil,
completion: Completion = nil)
```
--------------------------------
### xoauth2
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/AuthMethod.html
XOAUTH2 authentication. Requires a valid access token.
```swift
case xoauth2 = "XOAUTH2"
```
--------------------------------
### noAuthMethodsOrRequiresTLS Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
The preferred AuthMethods could not be found, or your server is sending back a STARTTLS command and requires a connection upgrade.
```swift
case noAuthMethodsOrRequiresTLS(hostname: String)
```
--------------------------------
### cramMD5
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/AuthMethod.html
CRAM-MD5 authentication.
```swift
case cramMD5 = "CRAM-MD5"
```
--------------------------------
### TLSMode.normal
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP/TLSMode.html
Upgrades the connection to TLS if STARTLS command is received, else sends mail without security.
```swift
case normal
```
--------------------------------
### Send email
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/index.html
Create a Mail object and use your SMTP handle to send it. To set the sender and receiver of an email, use the User struct.
```swift
let drLight = Mail.User(name: "Dr. Light", email: "drlight@gmail.com")
let megaman = Mail.User(name: "Megaman", email: "megaman@gmail.com")
let mail = Mail(
from: drLight,
to: [megaman],
subject: "Humans and robots living together in harmony and equality.",
text: "That was my ultimate wish."
)
smtp.send(mail) { (error) in
if let error = error {
print(error)
}
}
```
--------------------------------
### Send multiple mails
Source: https://github.com/kitura/swift-smtp/blob/master/README.md
Shows how to send multiple emails concurrently and provides optional callbacks for progress and completion.
```swift
let mail1: Mail = //...
let mail2: Mail = //...
smtp.send([mail1, mail2],
// This optional callback gets called after each `Mail` is sent.
// `mail` is the attempted `Mail`, `error` is the error if one occured.
progress: { (mail, error) in
},
// This optional callback gets called after all the mails have been sent.
// `sent` is an array of the successfully sent `Mail`s.
// `failed` is an array of (Mail, Error)--the failed `Mail`s and their corresponding errors.
completion: { (sent, failed) in
}
)
```
--------------------------------
### fileNotFound Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
File not found at path while trying to send file Attachment.
```swift
case fileNotFound(path: String)
```
--------------------------------
### Mail Initialization
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Mail.html
Initializes a Mail object with sender, recipients, subject, text, attachments, and additional headers.
```swift
public init(from: User,
to: [User],
cc: [User] = [],
bcc: [User] = [],
subject: String = "",
text: String = "",
attachments: [Attachment] = [],
additionalHeaders: [String: String] = [:])
```
--------------------------------
### badResponse Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Bad response received for command.
```swift
case badResponse(command: String, response: String)
```
--------------------------------
### Send Multiple Emails
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP.html
Send multiple emails.
```Swift
public func send(_ mail: [Mail], progress: ((Double) -> Void)? = nil, completion: ((Error?) -> Void)? = nil)
```
--------------------------------
### name Property
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Mail/User.html
The user’s name that is displayed in an email. Optional.
```swift
public let name: String?
```
--------------------------------
### md5HashChallengeFail Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Hashing server challenge with MD5 algorithm failed.
```swift
case md5HashChallengeFail
```
--------------------------------
### email Property
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Mail/User.html
The user’s email address.
```swift
public let email: String
```
--------------------------------
### Send Single Email
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP.html
Send an email.
```Swift
public func send(_ mail: Mail, completion: ((Error?) -> Void)? = nil)
```
--------------------------------
### base64DecodeFail Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Error decoding string.
```swift
case base64DecodeFail(string: String)
```
--------------------------------
### AuthMethod Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums.html
Declaration for the AuthMethod enumeration.
```swift
public enum AuthMethod : String
```
--------------------------------
### TLSMode Enum Cases
Source: https://github.com/kitura/swift-smtp/blob/master/docs/docsets/SwiftSMTP.docset/Contents/Resources/Documents/Structs/SMTP/TLSMode.html
The different modes for TLS connection security in SwiftSMTP.
```swift
case normal
```
```swift
case ignoreTLS
```
```swift
case requireTLS
```
```swift
case requireSTARTTLS
```
--------------------------------
### TLSConfiguration Structure Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs.html
Declaration of the TLSConfiguration structure.
```swift
public struct TLSConfiguration
```
--------------------------------
### TLSMode.ignoreTLS
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP/TLSMode.html
Send mail over plaintext and ignore STARTTLS commands and TLS options. Could throw an error if server requires TLS.
```swift
case ignoreTLS
```
--------------------------------
### User Structure
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Mail/User.html
Represents a sender or receiver of an email.
```swift
public struct User
```
--------------------------------
### invalidEmail Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Invalid email provided for User.
```swift
case invalidEmail(email: String)
```
--------------------------------
### convertDataUTF8Fail Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Error converting Data read from socket to a String.
```swift
case convertDataUTF8Fail(data: Data)
```
--------------------------------
### description Property
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Description of the SMTPError.
```swift
public var description: String { get }
```
--------------------------------
### Equality Operator
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/Attachment.html
Checks if two Attachment instances are equal.
```swift
public static func == (lhs: Attachment, rhs: Attachment) -> Bool
```
--------------------------------
### SMTP Structure Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs.html
Declaration of the SMTP structure.
```swift
public struct SMTP
```
--------------------------------
### noRecipients Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Mail has no recipients.
```swift
case noRecipients
```
--------------------------------
### Mail Structure Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs.html
Declaration of the Mail structure.
```swift
public struct Mail
```
--------------------------------
### Attachment Structure Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs.html
Declaration of the Attachment structure.
```swift
public struct Attachment
```
```swift
extension Attachment: Equatable
```
--------------------------------
### TLSMode Enum
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP.html
TLSMode enum for what form of connection security to enforce.
```Swift
public enum TLSMode
```
--------------------------------
### createEmailRegexFailed Error Case
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums/SMTPError.html
Failed to create RegularExpression that can check if an email is valid.
```swift
case createEmailRegexFailed
```
--------------------------------
### TLSMode.requireTLS
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Structs/SMTP/TLSMode.html
Only send mail after an initial successful TLS connection. Connection will fail if a TLS connection cannot be established. The default port, 587, will likely need to be adjusted depending on your server.
```swift
case requireTLS
```
--------------------------------
### Progress Type Alias
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Typealiases.html
Callback after each Mail is sent. Mail is the mail sent and Error is the error if it failed.
```swift
public typealias Progress = ((Mail, Error?) -> Void)?
```
--------------------------------
### SMTPError Declaration
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Enums.html
Declaration for the SMTPError enumeration.
```swift
public enum SMTPError : Error, CustomStringConvertible
```
--------------------------------
### Completion Type Alias
Source: https://github.com/kitura/swift-smtp/blob/master/docs/Typealiases.html
Callback after all Mails have been attempted. Mail is an array of successfully sent Mails. [(Mail, Error)] is an array of failed Mails and their corresponding Errors.
```swift
public typealias Completion = (([Mail], [(Mail, Error)]) -> Void)?
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.