Some examples of sending and receiving emails with Node.js.
This uses the following libraries:
- emailjs for sending email
- node-imap for receiving email
- mailparser for parsing received emails
Copy config.json.example
to config.json
and enter your email account details.
Run coffee send.coffee
to send yourself an email with an attachment.
Run coffee read.coffee
to receive the sent email and write the attachment back to disk with a new name.
Hi, thank you for making this. What version of imap and mailparser are you using? When I run this, send.js works fine but I get an error in read.js. I'm using imap@.075 and mailparser@0.2.31
PS C:\node\emailtest> node read.js
You have 7 messages in your INBOX
C:\node\emailtest\node_modules\imap\lib\imap.js:943
if (wp.id !== undefined && !/^(?:[\d]+[.]{0,1})*[\d]+$/.test(''+wp.id))
TypeError: Cannot read property 'id' of undefined
at ImapConnection._fetch (C:\node\emailtest\node_modules\imap\lib\imap.js:943:11)
at ImapConnection.fetch (C:\node\emailtest\node_modules\imap\lib\imap.js:917:15)
at ImapConnection. (C:\node\emailtest\read.js:43:28)
at ondata (C:\node\emailtest\node_modules\imap\lib\imap.js:662:30)
at CleartextStream.ondata (C:\node\emailtest\node_modules\imap\lib\imap.js:590:16)
at CleartextStream.emit (events.js:67:17)
at CleartextStream._push (tls.js:371:12)
at SecurePair.cycle (tls.js:734:20)
at EncryptedStream.write (tls.js:130:13)
at Socket.ondata (stream.js:38:26)