-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Toby Griffin
authored
Feb 16, 2017
1 parent
fa13766
commit 7a704f3
Showing
23 changed files
with
755 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public enum ClickTracking { | ||
/* | ||
Do not track clicks | ||
*/ | ||
case disabled | ||
/* | ||
Track clicks in HTML emails only | ||
*/ | ||
case htmlOnly | ||
/* | ||
Track clicks in HTML and plain text emails | ||
*/ | ||
case enabled | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import SMTP | ||
import Vapor | ||
|
||
extension EmailAddress: NodeRepresentable { | ||
|
||
public func makeNode(context: Context) throws -> Node { | ||
guard let name = name else { | ||
return Node(["email": Node(address)]) | ||
} | ||
return Node(["name": Node(name), "email": Node(address)]) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Footer to append to the email. Can be either plaintext or HTML. | ||
*/ | ||
public struct Footer { | ||
public enum ContentType { | ||
case html, plain | ||
} | ||
|
||
public let type: ContentType | ||
public let content: String | ||
|
||
public init(type: ContentType, content: String) { | ||
self.type = type | ||
self.content = content | ||
} | ||
} | ||
|
||
extension Footer: Equatable {} | ||
public func ==(lhs: Footer, rhs: Footer) -> Bool { | ||
return lhs.type == rhs.type | ||
&& lhs.content == rhs.content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public struct GoogleAnalytics { | ||
let source: String? | ||
let medium: String? | ||
let term: String? | ||
let content: String? | ||
let campaign: String? | ||
|
||
public init(source: String?, medium: String, term: String, content: String?, campaign: String?) { | ||
self.source = source | ||
self.medium = medium | ||
self.term = term | ||
self.content = content | ||
self.campaign = campaign | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public enum OpenTracking { | ||
/* | ||
Do not track opens | ||
*/ | ||
case disabled | ||
/* | ||
Track opens in emails. | ||
|
||
substitutionTag: This tag will be replaced by the open tracking pixel. | ||
*/ | ||
case enabled(substitutionTag: String?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Foundation | ||
import SMTP | ||
import Vapor | ||
|
||
public struct Personalization { | ||
|
||
/* | ||
The email recipients | ||
*/ | ||
public let to: [EmailAddress] | ||
/* | ||
The email copy recipients | ||
*/ | ||
public let cc: [EmailAddress] = [] | ||
/* | ||
The email blind copy recipients | ||
*/ | ||
public let bcc: [EmailAddress] = [] | ||
/* | ||
The email subject, overriding that of the Email, if set | ||
*/ | ||
public let subject: String? = nil | ||
/* | ||
Custom headers | ||
*/ | ||
public let headers: [String: String] = [:] | ||
/* | ||
Custom substitutions in the format ["tag": "value"] | ||
*/ | ||
public let substitutions: [String: String] = [:] | ||
/* | ||
Date to send the email, or `nil` if email to be sent immediately | ||
*/ | ||
public let sendAt: Date? = nil | ||
|
||
public init(to: [EmailAddress]) { | ||
self.to = to | ||
} | ||
|
||
} | ||
|
||
extension Personalization: NodeRepresentable { | ||
|
||
public func makeNode(context: Context) throws -> Node { | ||
var node = Node([:]) | ||
node["to"] = try Node(to.map { try $0.makeNode() }) | ||
if !cc.isEmpty { | ||
node["cc"] = try Node(cc.map { try $0.makeNode() }) | ||
} | ||
if !bcc.isEmpty { | ||
node["bcc"] = try Node(bcc.map { try $0.makeNode() }) | ||
} | ||
if let subject = subject { | ||
node["subject"] = Node(subject) | ||
} | ||
if !headers.isEmpty { | ||
node["headers"] = try headers.makeNode() | ||
} | ||
if !substitutions.isEmpty { | ||
node["substitutions"] = try substitutions.makeNode() | ||
} | ||
if let sendAt = sendAt { | ||
node["send_at"] = Node(sendAt.timeIntervalSince1970) | ||
} | ||
return node | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import SMTP | ||
|
||
extension SendGridEmail { | ||
|
||
/* | ||
Convert a basic Vapor SMTP.Email into a SendGridEmail | ||
*/ | ||
public convenience init(from: Email) { | ||
self.init(from: from.from, subject: from.subject, body: from.body) | ||
attachments = from.attachments | ||
personalizations = [Personalization(to: from.to)] | ||
} | ||
|
||
} |
Oops, something went wrong.