linux - How to create an email file? -
after fetchmail
fetches mails, new mails stored in file /var/mail/user
. can open file user
text editor vim
.
how can create such text-based email files? say, want send email contents:
from: sender <sender@xx.com> to: receiver <receiver@xx.com> subject: test subject contents: ... attached: file1.txt, file2.png, file3.pdf
the problem how make these formal text-based email.
besides, if have such email file. how can extract files(say, subjects, contents, attached files, etc.) command line tools. know can open program mutt
. can done using command line utility?
there bunch of standards need understand, email fundamentally text.
the file format in /var/spool/mail
or /var/mail/user
etc typically berkeley mbox
. not formally defined anywhere, consists of sequence of rfc5322 (née rfc822) email messages, each preceded from_
line, format of from %s
%c
%s
sender's email address (what see in return-path:
) , %c
date when message arrived. notice 2 spaces between format strings!
the toplevel email message rfc5322 on top of that, need understand mime.
you stumble on (e)smtp rfc5321 tangential question, know. notice how 821 , 822 (and later 2821 , 2822, , 5321 , 5322) have adjacent rfc numbers.
furthermore, there wild, wild west of non-standard headers, of nonetheless significant. dan bernstein's reference http://cr.yp.to/immhf.html lifesaver. general guideline, spammers typically copy/paste headers without understanding them; therefore, essential practice deliverability "don't that". in other words, if don't know header for, don't use it.
any modern programming language come libraries create , manipulate rfc5322 , mime, , mbox
too. creating message can send somewhere, don't need mbox
anyway, along lines of (pseudocode)
message = new mime({'subject': 'hello', 'from': 'me@example.net', 'to': 'my friend <you@example.com>'}); message.addbodypart('text/plain', 'hi fred.\nhow you?'); message.addbodypart('image/png', {'file': '/home/you/logo.png'}); smtp = new smtp('mail.example.net', 587, {'user': 'me', 'pass': 'xyzzy'}); smtp.send(message);
a multipart message looks describe in question, except there no specific header identify "attachments" , conceptually no "attachments", "body parts". here simple mime message show message in question like.
from: sender <sender@example.com> to: receiver <receiver@example.com> subject: test subject mime-version: 1.0 content-type: multipart/mixed; boundary="so_long_eflop" mime multipart message. nobody sees says here. --so_long_eflop content-type: text/plain; charset="utf-8" content-disposition: inline content-transfer-encoding: 7bit many mail clients display "main part" mime not define particular hierarchy. many mail clients generate text/plain rendering , text/html rendering of message type in, , recipient's mail client decide -- based on user preferences -- 1 display. anyway, not create example of here. "a text message picture attached", or, more precisely, mime message 2 body parts. oh, content-disposition: inline implied text/plain part. clients override or ignore disposition set sender anyway. --so_long_eflop content-type: image/png content-disposition: attachment content-transfer-encoding: base64 iam+not/attaching+a/real00picture+here/just/a/bunch0of/binary/goo=== --so_long_eflop--
Comments
Post a Comment