Skip to content

Commit

Permalink
adding CC/BCC support for Mailgun and SMTP
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Mar 2, 2019
1 parent d9542f2 commit b921d88
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 56 deletions.
97 changes: 44 additions & 53 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,143 +6,134 @@
"repositoryURL": "https://github.com/IBM-Swift/BlueCryptor.git",
"state": {
"branch": null,
"revision": "7865ad2f864633eb945dc77c43213fb34688bb3e",
"version": "1.0.5"
"revision": "fe59cc1fcabb390bf9b3b6dd4f8cacc897d91cf6",
"version": "1.0.24"
}
},
{
"package": "Socket",
"repositoryURL": "https://github.com/IBM-Swift/BlueSocket.git",
"state": {
"branch": null,
"revision": "e2f6aee81b9e316f61e173e8350cb69d7714ead8",
"version": "1.0.10"
"revision": "a40b405bdf32bc853307dd5dee8d00636e394013",
"version": "1.0.44"
}
},
{
"package": "SSLService",
"repositoryURL": "https://github.com/IBM-Swift/BlueSSLService.git",
"state": {
"branch": null,
"revision": "f4c012b783f8809d4e6597b304357c5324ff459b",
"version": "1.0.10"
}
},
{
"package": "CommonCrypto",
"repositoryURL": "https://github.com/IBM-Swift/CommonCrypto.git",
"state": {
"branch": null,
"revision": "9156d238dbc4c15455b77b45e721b2bb0b995e31",
"version": "1.0.0"
"revision": "6910763b0dfa6f95a75217215d8cdce3ee11a6ae",
"version": "1.0.44"
}
},
{
"package": "Console",
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "5b9796d39f201b3dd06800437abd9d774a455e57",
"version": "3.0.2"
"revision": "d6cf07af59ae63cd95c4b5f98cf1f25627750fd1",
"version": "3.1.0"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "7f56a09995bf3c8df562be456bdcda405d9d0678",
"version": "3.4.1"
"revision": "33e6b1a5fe0cfd06353022fe03a8da7bf7a1fb01",
"version": "3.6.0"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "4b85405430df1892ee3aa1554bdb477e96cf46ad",
"version": "3.2.0"
"revision": "45bb12d13cdec80dbd1cc0685ea002e51ab83439",
"version": "3.3.2"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "acdd4d3384ec0122dcfcca8d23d9054a2860ffba",
"version": "1.2.0"
"revision": "8f352c8e66dab301ab9bfef912a01ce1361ba1e4",
"version": "1.3.3"
}
},
{
"package": "HTTP",
"repositoryURL": "https://github.com/vapor/http.git",
"state": {
"branch": null,
"revision": "8123ea00e9858b369cd168d0303d33e7d3804d19",
"version": "3.0.7"
"revision": "b57005e0de30ba36372ac41bfce1ac12b2bc3272",
"version": "3.1.8"
}
},
{
"package": "LoggerAPI",
"repositoryURL": "https://github.com/IBM-Swift/LoggerAPI.git",
"state": {
"branch": null,
"revision": "5041f2673aa75d6e973d9b6bd3956bc5068387c8",
"version": "1.7.3"
"revision": "d0ccb4158b83f8692531892a9c894bb757593c6f",
"version": "1.8.0"
}
},
{
"package": "Multipart",
"repositoryURL": "https://github.com/vapor/multipart.git",
"state": {
"branch": null,
"revision": "e57007c23a52b68e44ebdfc70cbe882a7c4f1ec3",
"version": "3.0.2"
"revision": "bd7736c5f28e48ed8b683dcc9df3dcd346064c2b",
"version": "3.0.3"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
"state": {
"branch": null,
"revision": "3219e328491b0853b8554c5a694add344d2c6cfb",
"version": "3.0.1"
"revision": "626190ddd2bd9f967743b60ba6adaf90bbd2651c",
"version": "3.0.2"
}
},
{
"package": "SendGrid",
"repositoryURL": "https://github.com/vapor-community/sendgrid-provider.git",
"state": {
"branch": null,
"revision": "3b71cae7ed953a128a7bb0381b80b31bc7f1d8e5",
"version": "3.0.5"
"revision": "4fca9d02fee4f343666e73651fedd4d26ed048e8",
"version": "3.0.6"
}
},
{
"package": "Service",
"repositoryURL": "https://github.com/vapor/service.git",
"state": {
"branch": null,
"revision": "281a70b69783891900be31a9e70051b6fe19e146",
"version": "1.0.0"
"revision": "4907311d7d7f609365982fa302b8b17ffdeb46da",
"version": "1.0.1"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "695afc5205aaa49fca092b94b479ff71c43d9d3c",
"version": "1.8.0"
"revision": "87dbd0216c47ea2e7ddb1b545271b716e03b943e",
"version": "1.13.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "6617eb0d3afcb12170594968df01ca63afb58ac5",
"version": "1.2.0"
"revision": "0f3999f3e3c359cc74480c292644c3419e44a12f",
"version": "1.4.0"
}
},
{
Expand Down Expand Up @@ -177,62 +168,62 @@
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "43b57b5861d5181b906ac6411d28645e980bb638",
"version": "1.0.1"
"revision": "aff2d6fc65bfd04579b0201b31a8d6720239c1cf",
"version": "1.1.1"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "57cf7fb9c1a1014c50bc05123684a9139ad44127",
"version": "1.0.3"
"revision": "932024f363ee5ff59059cf7d67194a1c271d3d0c",
"version": "1.0.5"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
"state": {
"branch": null,
"revision": "ab6c5a352d97c8687b91ed4963aef8e7cfe0795b",
"version": "2.0.0"
"revision": "4de213cf319b694e4ce19e5339592601d4dd3ff6",
"version": "2.1.1"
}
},
{
"package": "Vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "6b07105a3899fbbae194ee3eb82f54debe502221",
"version": "3.0.6"
"revision": "c86ada59b31c69f08a6abd4f776537cba48d5df6",
"version": "3.3.0"
}
},
{
"package": "Mailgun",
"repositoryURL": "https://github.com/twof/VaporMailgunService.git",
"state": {
"branch": null,
"revision": "135f522866cc2e45734a0ad9b78dcfb85450e4fc",
"version": "1.2.0"
"revision": "353706a5c73f4aa79494a9bc681113bd5400017f",
"version": "1.5.0"
}
},
{
"package": "VaporTestTools",
"repositoryURL": "https://github.com/LiveUI/VaporTestTools.git",
"state": {
"branch": null,
"revision": "e07ce263257463f2f2af9e640f81eb95a72760e4",
"version": "0.1.5"
"revision": "135d02e2e2a632c134567754d65ce2afe262bab3",
"version": "0.1.7"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/vapor/websocket.git",
"state": {
"branch": null,
"revision": "141cb4d3814dc8062cb0b2f43e72801b5dfcf272",
"version": "1.0.1"
"revision": "21eb4773e25a8ff96fe347a31fe106900a69fa6a",
"version": "1.1.1"
}
}
]
Expand Down
10 changes: 9 additions & 1 deletion Sources/MailCore/Extensions/Message+Mailgun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ extension Mailer.Message {

/// Message as a Mailgun content
func asMailgunContent() -> Mailgun.Message {
return Mailgun.Message(from: from, to: to, subject: subject, text: text, html: html)
return Mailgun.Message(
from: from,
to: to,
cc: cc?.joined(separator: ","),
bcc: bcc?.joined(separator: ","),
subject: subject,
text: text,
html: html
)
}

}
4 changes: 3 additions & 1 deletion Sources/MailCore/Extensions/Message+SMTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extension Mailer.Message {
let fromUser = Mail.User(email: from)

let toUser = Mail.User(email: to)
let ccUsers = (cc ?? []).map({ Mail.User(email: $0) })
let bccUsers = (bcc ?? []).map({ Mail.User(email: $0) })

let attachments: [Attachment]
if let html = html {
Expand All @@ -25,7 +27,7 @@ extension Mailer.Message {
attachments = []
}

let mail = Mail(from: fromUser, to: [toUser], subject: subject, text: text, attachments: attachments)
let mail = Mail(from: fromUser, to: [toUser], cc: ccUsers, bcc: bccUsers, subject: subject, text: text, attachments: attachments)
return mail
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/MailCore/Extensions/Message+SendGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extension Mailer.Message {
]
)
}

if cc != nil || bcc != nil {
print("SendGrid client doesn't yet support CC or BCC")
}

let message = SendGridEmail(
personalizations: [Personalization(to: [EmailAddress(email: to)])],
Expand Down
6 changes: 5 additions & 1 deletion Sources/MailCore/MailCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ public class Mailer: MailerService {
public struct Message {
public let from: String
public let to: String
public let cc: [String]?
public let bcc: [String]?
public let subject: String
public let text: String
public let html: String?

/// Message init
public init(from: String, to: String, subject: String, text: String, html: String? = nil) {
public init(from: String, to: String, cc: [String]? = nil, bcc: [String]? = nil, subject: String, text: String, html: String? = nil) {
self.from = from
self.to = to
self.cc = cc
self.bcc = bcc
self.subject = subject
self.text = text
self.html = html
Expand Down

0 comments on commit b921d88

Please sign in to comment.