Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send attachments with SMTP #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LinusGeffarth
Copy link
Contributor

@LinusGeffarth LinusGeffarth commented May 8, 2020

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: "from@example.com",
            to: "to@example.com",
            subject: "Example subject", text: "Example subject",
            html: String(data: view.data, encoding: .utf8) ?? "",
            attachments: attachments
        )
    }
}

Again, additions only, shouldn't break anything.

@rafiki270
Copy link
Contributor

Would you mind updating the documentation please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants