Create a .eml (email) file in Java

前端 未结 5 821
不思量自难忘°
不思量自难忘° 2020-12-01 07:50

Anybody knows how to do this? I got all the information of the email (body, subject, from , to, cc, bcc) and need to generate an .eml file out of it.

5条回答
  •  生来不讨喜
    2020-12-01 08:35

    EML files are just plain text files. The headers are separated from the body by a blank line. Headers look like this:

    From: "DR CLEMENT OKON" 
    To: "You" 
    Subject: REQUEST FOR URGENT BUSINESS RELATIONSHIP 
    Date: Tue, 30 Sep 2008 09:42:47 -0400
    

    For more info, the official spec is RFC 2822. It's actually not as hard to read as some RFCs.

    Edit: When I said "plain text" I should have thought for a second. I really meant plain ASCII - and not the 8-bit "extended ASCII" either - just up to character 127. If you want more than seven bits, you need some kind of encoding and things get complicated.

提交回复
热议问题