somnisoft / smtp-client

SMTP Client Library in C
Creative Commons Zero v1.0 Universal
109 stars 31 forks source link

Corrupted pdf attachments #5

Closed Poyias closed 4 years ago

Poyias commented 4 years ago

Hi there,

This is a great smtp-client and thanks :) I have been trying to add .pdf attachments to the email. I am using this: smtp_attachment_add_path(this->smtp, "test.pdf", "source\test.pdf");

If I try to attach a ".txt" file it works great but doing it with a pdf the emails are being sent but the attached pdfs are corrupted and cannot open.

Thanks, Andreas

Poyias commented 4 years ago

I tried the one below, the email is succesfully being sent and only the txt file can open. The pdf files are corrupted: smtp_attachment_add_path(this->smtp, "test.pdf", "source\test.pdf"); smtp_attachment_add_path(this->smtp, "blah.txt", "source\blah.txt"); FILE *fp; fp = fopen("source\test.pdf", "r"); smtp_attachment_add_fp(this->smtp, "test.pdf", fp);

somnisoft commented 4 years ago

It looks like this issue only affects Windows. In your example, please change "r" to "rb" when opening the PDF file with fopen(). I also updated the path function to use rb.

Poyias commented 4 years ago

Thanks for the quick reply. I tried your changes but I still see the same problem.

Poyias commented 4 years ago

Problem solved. You were right, the only problem was "rb" in the end. Thanks a lot!!