nimMime
nimMime copied to clipboard
When I attach a PDF file, it is corrupted in the received message
Hello,
Thanks a lot for this lib, it helps a lot.
I tried the code from the readme with a basic pdf file:
In the message I received, it ends up like this: input-1.pdf
Any idea about what is happening? (I have not yet tried another smtp provider, this is my next step => tried, same result).
Here is the full code I have:
import std/[smtp, os, strutils]
import mime
proc sendTestEmail*() =
let smtpRelayHost = getEnv("SMTP_RELAY_HOST", "")
let smtpRelayPort = parseInt(getEnv("SMTP_RELAY_PORT", ""))
let smtpUsername = getEnv("SMTP_USERNAME", "")
let smtpPassword = getEnv("SMTP_PASSWORD", "")
let mailFrom = getEnv("MAIL_FROM", "")
let sender = getEnv("SENDER", "")
let recipient = getEnv("RECIPIENT", "")
## Compose your mime message
var
pdf = newAttachment(readFile("/Users/sehret/dev/input.pdf"),
filename = "input.pdf")
pdf.encodeQuotedPrintables()
var email = newEmail("Hello friend", "Iñtërnâtiônàlizætiøn☃💩",
sender, @[recipient],
attachments = @[pdf])
## Send it using smtp.nim
var smtpConn = newSmtp(
useSsl = true,
debug = true
)
smtpConn.connect(smtpRelayHost, Port smtpRelayPort)
smtpConn.auth(smtpUsername, smtpPassword)
smtpConn.sendMail(mailFrom, @[recipient],
$email.finalize())
smtpConn.close()
Cheers!
Hey @SiegfriedEhret, thank you for this issue!
Can you try to use:
pdf.encodeBase64()
instead of encodeQuotedPrintables()
i wonder if this works.
In theory, encodeQuotedPrintables should also work for this, but could produce larger attachments.
i guess there is a bug in encodeQuotedPrintables but not checked yet.
I found the issue, will make a release soon
Thanks a lot!
It worked well with pdf.encodeBase64()
:).
TODO use the new (correct and fast) https://github.com/enthus1ast/nimQuotedPrintables