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)
SMTPKitten
To get started, add the SMTPKitten dependency:
And add it as a dependency of your target:
Create a connection
Sending Emails
Before sending an email, first contruct a
Mail
object. Then, callsendMail
on the client.You can also use a result builder pattern for creating emails.
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.