MailCore icon indicating copy to clipboard operation
MailCore copied to clipboard

Send attachments with SMTP

Open LinusGeffarth opened this issue 5 years ago • 1 comments

Example usage with a pdf file from the Public folder:

let directory = DirectoryConfig.detect()
let configDir = "Public/storage/pdf"
let pdfData = try Data(contentsOf: URL(fileURLWithPath: directory.workDir)
    .appendingPathComponent(configDir, isDirectory: true)
    .appendingPathComponent(some.pdf, isDirectory: false))

let attachments: [Attachment] = [
    Attachment(data: pdfData, mime: "application/pdf", name: "some.pdf", inline: false)
]
return try req.view().render("my-template").map { (view) -> [Mailer.Message] in
    return users.map { user in
        return Mailer.Message(
            from: "[email protected]",
            to: "[email protected]",
            subject: "Example subject", text: "Example subject",
            html: String(data: view.data, encoding: .utf8) ?? "",
            attachments: attachments
        )
    }
}

Again, additions only, shouldn't break anything.

LinusGeffarth avatar May 08 '20 09:05 LinusGeffarth

Would you mind updating the documentation please?

rafiki270 avatar May 08 '20 10:05 rafiki270