SMTPKitten

0.2.3

Joannis/SMTPKitten

What's New

0.2.3

2024-01-25T17:17:16Z

What's Changed

  • func buildBlock(_ components: [MailContentConvertible]) by @tierracero in #10

New Contributors

Full Changelog: 0.2.1...0.2.3

SMTPKitten

To get started, add the SMTPKitten dependency:

.package(url: "https://github.com/joannis/SMTPKitten.git", from: "0.2.0"),

And add it as a dependency of your target:

.product(name: "SMTPKitten", package: "SMTPKitten"),

Create a connection

let client = try await SMTPClient.connect(
    hostname: "smtp.example.com",
    ssl: .startTLS(configuration: .default)
)
try await client.login(
    user: "noreply@example.com",
    password: "pas$w0rd"
)

Sending Emails

Before sending an email, first contruct a Mail object. Then, call sendMail on the client.

let mail = Mail(
    from: MailUser(name: "My Mailer", email: "noreply@example.com"),
    to: [MailUser(name: "John Doe", email: "john.doe@example.com")],
    subject: "Welcome to our app!",
    contentType: .plain,
    text: "Welcome to our app, you're all set up & stuff."
)

try await client.sendMail(mail)

You can also use a result builder pattern for creating emails.

let image = try Data(contentsOf: URL(filePath: imagePath))
let attachment = try Data(contentsOf: URL(filePath: attachmentPath))

let mail = Mail(
    from: MailUser(name: "SMTPKitten Tester", email: "noreply@example.com"),
    to: ["joannis@unbeatable.software"],
    subject: "Welcome to our app!"
) {
    "Welcome to our app, you're all set up & stuff."
    Mail.Image.png(image, filename: "Screenshot.png")
    Mail.Content.alternative("**End** of mail btw.", html: "<b>End</b> of mail btw.")
    Mail.Attachment(attachment, mimeType: "application/pdf")
}

try await client.sendMail(mail)

Community

Join our Discord for any questions and friendly banter.

If you need hands-on support on your projects, our team is available at hello@unbeatable.software.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

Last updated: Thu Apr 04 2024 15:28:52 GMT-0900 (Hawaii-Aleutian Daylight Time)