Forums

Sending files via email in Django

Hi,

I have the following situation:

I have developed a web app where people can do kind of a questionnaire, which processes the answers and gives feedback . The application is storing the results of the questionnaire in a database but it is totally anonymous so there is no registration etc. I do however want to give the possibility to the users to send their results as pdf to an email address.

Now to generate the pdf I use the results stored as session variables and integrate them in a pdf document that isI generated with Reportlab but I have to save the pdf file somewhere in my project folder to send it as attachment via email. As the filename is always the same and I'm not able to distinguish between users I was wondering if this could be problematic when multiple users are using the app right at the same time. Will there be a confusion with the session variables and the one pdf file stored in my project folder?

How can I solve this problem?

Thanks for support

Bob

Yes. It seems likely that you could end up emailing a PDF for one user to another one. Your best bet would be to use different file names for each generated PDF and only email that one to the user in question.

Indeed but how should I name the different pdfs if I don't have any information about the user ? Could it be possible to use their IP Addresses? How could I do this?

You could store a unique filename on the session. Maybe it could be a hash of the session variables that you use to generate it.

Thanks for your help Glenn! I succeeded to create dynamic file names by using the session id. Everything works fine now.