diff --git a/Package.resolved b/Package.resolved index fba80bc..c438463 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swift-server/async-http-client.git", "state" : { - "revision" : "78db67e5bf4a8543075787f228e8920097319281", - "version" : "1.18.0" + "revision" : "291438696abdd48d2a83b52465c176efbd94512b", + "version" : "1.20.1" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/async-kit.git", "state" : { - "revision" : "a61da00d404ec91d12766f1b9aac7d90777b484d", - "version" : "1.17.0" + "revision" : "7ece208cd401687641c88367a00e3ea2b04311f1", + "version" : "1.19.0" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/console-kit.git", "state" : { - "revision" : "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4", - "version" : "4.6.0" + "revision" : "a31f44ebfbd15a2cc0fda705279676773ac16355", + "version" : "4.14.1" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/multipart-kit.git", "state" : { - "revision" : "1adfd69df2da08f7931d4281b257475e32c96734", - "version" : "4.5.4" + "revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8", + "version" : "4.6.0" } }, { @@ -41,17 +41,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/routing-kit.git", "state" : { - "revision" : "611bc45c5dfb1f54b84d99b89d1f72191fb6b71b", - "version" : "4.7.2" + "revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e", + "version" : "4.9.0" } }, { "identity" : "smtpkitten", "kind" : "remoteSourceControl", - "location" : "https://github.com/joannis/SMTPKitten.git", + "location" : "https://github.com/Joannis/SMTPKitten.git", "state" : { - "revision" : "84699b87957068ca2eb69ecd5c2ed7f3ff4a9604", - "version" : "0.1.9" + "revision" : "0b7cc976c7291b55ef1550ec3e48409ac5855c2c", + "version" : "0.2.2" } }, { @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-algorithms.git", "state" : { - "revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e", - "version" : "1.0.0" + "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", + "version" : "1.2.0" } }, { @@ -68,35 +68,35 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-atomics.git", "state" : { - "revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10", - "version" : "1.1.0" + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" } }, { - "identity" : "swift-backtrace", + "identity" : "swift-collections", "kind" : "remoteSourceControl", - "location" : "https://github.com/swift-server/swift-backtrace.git", + "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956", - "version" : "1.3.3" + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" } }, { - "identity" : "swift-collections", + "identity" : "swift-crypto", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections.git", + "location" : "https://github.com/apple/swift-crypto.git", "state" : { - "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version" : "1.0.4" + "revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb", + "version" : "3.3.0" } }, { - "identity" : "swift-crypto", + "identity" : "swift-http-types", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-crypto.git", + "location" : "https://github.com/apple/swift-http-types", "state" : { - "revision" : "33a20e650c33f6d72d822d558333f2085effa3dc", - "version" : "2.5.0" + "revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65", + "version" : "1.0.3" } }, { @@ -104,8 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", - "version" : "1.5.2" + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-metrics.git", "state" : { - "revision" : "34025104068262db0cc998ace178975c5ff4f36b", - "version" : "2.4.0" + "revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1", + "version" : "2.4.1" } }, { @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "6213ba7a06febe8fef60563a4a7d26a4085783cf", - "version" : "2.54.0" + "revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982", + "version" : "2.64.0" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-extras.git", "state" : { - "revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997", - "version" : "1.19.0" + "revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", + "version" : "1.22.0" } }, { @@ -140,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-http2.git", "state" : { - "revision" : "a8ccf13fa62775277a5d56844878c828bbb3be1a", - "version" : "1.27.0" + "revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87", + "version" : "1.30.0" } }, { @@ -149,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "e866a626e105042a6a72a870c88b4c531ba05f83", - "version" : "2.24.0" + "revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", + "version" : "2.26.0" } }, { @@ -158,26 +158,35 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-transport-services.git", "state" : { - "revision" : "41f4098903878418537020075a4d8a6e20a0b182", - "version" : "1.17.0" + "revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce", + "version" : "1.20.1" } }, { "identity" : "swift-numerics", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-numerics", + "location" : "https://github.com/apple/swift-numerics.git", "state" : { "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", "version" : "1.0.2" } }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "025bcb1165deab2e20d4eaba79967ce73013f496", + "version" : "1.2.1" + } + }, { "identity" : "vapor", "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/vapor.git", "state" : { - "revision" : "9a340de4995e5a9dade4ff4c51cd2e6ae30c12d6", - "version" : "4.77.0" + "revision" : "3a7da193a2937472b252b8db210897e7abf37b47", + "version" : "4.92.4" } }, { diff --git a/Package.swift b/Package.swift index 929de17..54d1146 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( targets: ["VaporSMTPKit"]), ], dependencies: [ - .package(url: "https://github.com/Joannis/SMTPKitten.git", "0.1.0" ..< "0.2.0"), + .package(url: "https://github.com/Joannis/SMTPKitten.git", "0.2.0" ..< "0.2.3"), .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), ], targets: [ diff --git a/Sources/VaporSMTPKit/VaporSMTPKit.swift b/Sources/VaporSMTPKit/VaporSMTPKit.swift index 4208c60..80aa553 100644 --- a/Sources/VaporSMTPKit/VaporSMTPKit.swift +++ b/Sources/VaporSMTPKit/VaporSMTPKit.swift @@ -2,19 +2,20 @@ import Vapor import SMTPKitten extension Application { + public func sendMail( _ mail: Mail, withCredentials credentials: SMTPCredentials, preventedDomains: Set = ["example.com"] - ) -> EventLoopFuture { - return sendMails([mail], withCredentials: credentials, preventedDomains: preventedDomains) + ) async throws { + try await sendMails([mail], withCredentials: credentials, preventedDomains: preventedDomains) } public func sendMails( _ mails: [Mail], withCredentials credentials: SMTPCredentials, preventedDomains: Set = ["example.com"] - ) -> EventLoopFuture { + ) async throws { func filterMailAddress(_ address: MailUser) -> Bool { for domain in preventedDomains { if address.email.contains(domain) { @@ -25,7 +26,7 @@ extension Application { return true } - let mails = mails.compactMap { mail -> Mail? in + let filteredMails = mails.compactMap { mail -> Mail? in var mail = mail mail.to = mail.to.filter(filterMailAddress) @@ -39,21 +40,26 @@ extension Application { return mail } - - return SMTPClient.connect( + let client = try await SMTPClient.connect( hostname: credentials.hostname, port: credentials.port, - ssl: credentials.ssl, - eventLoop: self.eventLoopGroup.next() - ).flatMap { client in - client.login( - user: credentials.email, - password: credentials.password - ).flatMap { - let sent = mails.map(client.sendMail) - return EventLoopFuture.andAllSucceed(sent, on: self.eventLoopGroup.next()) + ssl: credentials.ssl + ) + + try await client.login( + user: credentials.email, + password: credentials.password + ) + + let sent: () = await withThrowingTaskGroup(of: Void.self) { group in + for mail in filteredMails { + group.addTask { + try await client.sendMail(mail) + } } } + + _ = sent } }