onevcat/Hedwig là một trong những repo phía máy chủ mà TopGit theo dõi, hiện có 1.1k sao, viết chủ yếu bằng Swift. Send email to any SMTP server like a boss, in Swift and cross-platform
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Hedwig is a Swift package which supplies a set of high level APIs to allow you sending email to an SMTP server easily. If you are planning to send emails from your next amazing Swift server app, Hedwig might be a good choice.
Features
Connect to all SMTP servers, through whether plain, SSL or TLS (STARTTLS) port.
Authentication with PLAIN, CRAM-MD5, LOGIN or XOAUTH2.
Send email with HTML body and attachments.
Customize validation method and mail header, to track your mail campaign.
Queued mail sending, without blocking your app. You can even send mails concurrently.
Works with Swift Package Manager, in the latest Swift syntax and cross-platform.
Fully tested and documented.
Using Forward Email
Forward Email is a 100% open-source and privacy-focused email service. It works out of the box with Hedwig via SMTP.
Use coupon code GITHUB at https://forwardemail.net for 100% off.
let hedwig = Hedwig(
hostName: "smtp.forwardemail.net",
user: "[email protected]",
password: "your-generated-password",
port: 465,
secure: .ssl
)
let mail = Mail(
text: "Hello from Hedwig + Forward Email!",
from: "[email protected]",
to: "[email protected]",
subject: "Hello World"
)
hedwig.send(mail) { error in
if error != nil { /* Error happened */ }
}
Replace [email protected] with your alias and your-generated-password with the password generated in your Forward Email dashboard. See the Forward Email FAQ and source code for more details.
Then run swift build whenever you get prepared. (Also remember to grab a cup of coffee 😄)
You can find more information on how to use Swift Package Manager in Apple's official page.
Usage
Sending text only email
let hedwig = Hedwig(hostName: "smtp.example.com", user: "[email protected]", password: "password")
let mail = Mail(
text: "Across the great wall we can reach every corner in the world.",
from: "[email protected]",
to: "[email protected]",
subject: "Hello World"
)
hedwig.send(mail) { error in
if error != nil { /* Error happened */ }
}
Sending HTML email
let hedwig = Hedwig(hostName: "smtp.example.com", user: "[email protected]", password: "password")
let attachment = Attachment(htmlContent: "<html><body><h1>Title</h1><p>Content</p></body></html>")
let mail = Mail(
text: "Fallback text",
from: "[email protected]",
to: "[email protected]",
subject: "Title",
attachments: [attachment]
)
hedwig.send(mail) { error in
if error != nil { /* Error happened */ }
}
CC and BCC
let hedwig = Hedwig(hostName: "smtp.example.com", user: "[email protected]", password: "password")
let mail = Mail(
text: "Across the great wall we can reach every corner in the world.",
from: "[email protected]",
to: "[email protected]",
cc: "Wei Wang <[email protected]>, [email protected]", // Addresses will be parsed for you
bcc: "My Group: [email protected], [email protected];", // Even with group syntax
subject: "Hello World"
)
hedwig.send(mail) { error in
if error != nil { /* Error happened */ }
}
Using different SMTP settings (security layer, auth method and etc.)
let hedwig = Hedwig(
hostName: "smtp.example.com",
user: "[email protected]",
password: "password",
port: 1234, // Determined from secure layer by default
secure: .plain, // .plain (Port 25) | .ssl (Port 465) | .tls (Port 587) (default)
validation: .default, // You can set your own certificate/cipher/protocols
domainName: "onevcat.com", // Used when saying hello to STMP Server
authMethods: [.plain, .login] // Default: [.plain, .cramMD5, .login, .xOauth2]
)
Send mails with inline image and other attachment
let imagePath = "/tmp/image.png"
// You can create an attachment from a local file path.
let imageAttachment = Attachment(
filePath: imagePath,
inline: true,
// Add "Content-ID" if you need to embed this image to another attachment.
additionalHeaders: ["Content-ID": "hedwig-image"]
)
let html = Attachment(
htmlContent: "<html><body>A photo <img src=\"cid:hedwig-image\"/></body></html>",
// If imageAttachment only used embeded in HTML, I recommend to set it as related.
related: [imageAttachment]
)
// You can also create attachment from raw data.
let data = "{\"key\": \"hello world\"}".data(using: .utf8)!
let json = Attachment(
data: data,
mime: "application/json",
name: "file.json",
inline: false // Send as standalone attachment.
)
let mail = Mail(
text: "Fallback text",
from: "[email protected]",
to: "[email protected]",
subject: "Check the photo and json file!",
attachments: [html, json]
hedwig.send(mail) { error in
if error != nil { /* Error happened */ }
}
Send multiple mails
let mail1: Mail = //...
let mail2: Mail = //...
hedwig.send([mail1, mail2],
progress: { (mail, error) in
if error != nil {
print("\(mail) failed. Error: \(error)")
}
},
completion: { (sent, failed) in
for mail in sent {
print("Sent mail: \(mail.messageId)")
}
for (mail, error) in failed {
print("Mail \(mail.messageId) errored: \(error)")
}
}
)
Help and Questions
Visit the documentation page for full API reference.
You could also run the tests (swift test) to see more examples to know how to use Hedwig.
If you have found the framework to be useful, please consider a donation. Your kind contribution will help me afford more time on the project.
Or you are a Bitcoin fan and want to treat me a cup of coffe, here is my wallet address:
1MqwfsxBJ5pJX4Qd2sRVhK3dKTQrWYooG5
FAQ
I cannot send mails with Gmail SMTP.
Gmail uses an application specific password. You need to create one and use the specified password when auth. See this.
I need to add/set some additonal header in the mail.
Both Mail and Attachment accept customizing header fields. Pass your headers as additionalHeaders when creating the mail or attachment and Hedwig will handle it.
Can I use it in iOS?
At this time Swift Package Manager has no support for iOS, watchOS, or tvOS platforms. So the answer is no. But this framework is not using anything only in iOS (like UIKit), so as soon as Swift Package Manager supports iOS, you can use it there too.
Tell me about the name and logo of Hedwig
Yes, Hedwig (bird) was Harry Potter's pet Snowy Owl. The logo of Hedwig (this framework) is created by myself and it pays reverence to the novels and movies.
Other questions
Submit an issue if you find something wrong. Pull requests are warmly welcome, but I suggest to discuss first.
You can also follow and contact me on Twitter or Sina Weibo.
Enjoy sending your emails
License
Hedwig is released under the MIT license. See LICENSE for details.
onevcat/Hedwig thuộc nhóm Backend trên TopGit, cùng 5 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về onevcat/Hedwig ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/onevcat/Hedwig là nguồn chính thức.
onevcat/Hedwig có bao nhiêu sao?
onevcat/Hedwig có 1.1k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/onevcat/Hedwig. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
onevcat/Hedwig có những chủ đề gì?
GitHub topics của onevcat/Hedwig: "cross-platform", "mail", "server", "smtp", "swift". TopGit xếp repo vào nhóm Backend.
onevcat/Hedwig có phải mã nguồn mở không?
Có — onevcat/Hedwig phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/onevcat/Hedwig.
onevcat/Hedwig có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho onevcat/Hedwig. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
onevcat/Hedwig còn đang phát triển không?
Commit gần nhất trên onevcat/Hedwig là 6 tháng trước (theo timestamp GitHub). Repo có 68 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Hedwig có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về Hedwig.