Page 1 of 1

Email with smtp a pdf

Posted: Monday 5th July 2021 11:01pm
by sadams54
I have a working smtp setup for my program. What does not work is when I attach a pdf file it sends but it is unreadable as it is sent as plain text. I can't find a list of mime types and most notably the mime type to set in the smtp client for sending a pdf file. Any help?

Re: Email with smtp a pdf

Posted: Tuesday 6th July 2021 12:05am
by vuott
sadams54 wrote: Monday 5th July 2021 11:01pm ... the mime type to set in the smtp client for sending a pdf file.
...maybe: :|

https://stackoverflow.com/questions/312 ... -pdf-files
https://mimeapplication.net/pdf

Re: Email with smtp a pdf

Posted: Tuesday 6th July 2021 12:24am
by sadams54
application/pdf is what I already set the mime type to. Which is what your link suggests although not specifically for gambas. But I already have it as I thought it should be. I should have made it more clear. Below is the line doing the attachment.

e.Add(User.Home & "/" & StoreName & SlsID & ".pdf", "application/pdf", StoreName & SlsID & ".pdf")

it works but the mime type is not right as the file can't be opened on the other end.

Re: Email with smtp a pdf

Posted: Tuesday 6th July 2021 9:34am
by cogier
I had a look at this and discovered (thanks to gbWilly) that you need to load the PDF file, and then it works as expected. Try the following:-
e.Add(File.Load(User.Home &/ StoreName & SlsID & ".pdf"), "application/pdf", StoreName & SlsID & ".pdf")
Note that &/ will add a slash, if it is needed. No need for & "/" & which will add a slash if it is needed or not.

Re: Email with smtp a pdf

Posted: Tuesday 6th July 2021 6:36pm
by sadams54
You are truly the god of gambas. I had a feeling it was something easy but I was looking in the wrong spot. Thank you for the help it is working perfectly now. This was for a Point of Sale that I developed and use written in gambas. Keep the great work up.

Re: Email with smtp a pdf

Posted: Thursday 8th July 2021 2:20pm
by gbWilly
I had a look at this and discovered (thanks to gbWilly) that you need to load the PDF file, and then it works as expected. Try the following:-
That's a very old post of mine ;)

Re: Email with smtp a pdf

Posted: Friday 9th July 2021 2:01pm
by cogier
That's a very old post of mine
Nice to know you are still around!