In email applications should the text of the cover letter be stated directly in the email or be attached in a separate file? When applying for example to a postdoc position, is it appropriate to write the text of the cover letter directly into the email, or should it be attached as a seperate file?

One advantage of stating the content of the cover letter directly in the email I could see is that there are good changes that the potential future employer reads it before opening any other ducuments, such as the curriculum vitae, list of publications, etc that might be attached.
I would advise to make the email brief, and make sure that the motivation letter is the first attachment. Often, motivation letters are printed (at least the ones which wind up in the final round) and a properly formatted letter looks better than a printed email.