I'm a beginner at node.js, but i want to know: is there any way to send folders with nodemailer?
I found a lot of attachment types like: path: 'F:asdasd\asd.rar' But i don't want only one file, i want the entire folder. Thanks for the help!
As per any manual client! You can't attach a folder directly! However you can attach multiple files! Or zip the folder and attach it!
Zipping can be the right best choice! However we can have two choices here! Zipping or attaching multiple files! Because we are programming we can do any of that easily! And in the way that we want!
Another choice would be to use a cloud storage and just add the link per the email message!
Before tackling this! It's nice to talk about how an email is send! And also the size limit!
NOTE: the answer go in two parts! How emails works! and How to attach a folder!
Protocols SMTP, EMAP AND POP are used between an email server (One of google servers for the gmail service)! And an email client (gmail web app client, thunderbird)!
You can check each protocol here
In resume:
SMTP
Simple Mail Transfer Protocol (SMTP) is the standard protocol for sending emails across the Internet.
IMAP
The Internet Message Access Protocol (IMAP) is a mail protocol used for accessing email on a remote web server from a local client. IMAP allow multi clients simultanous access!
POP3
Post Office Protocol version 3 (POP3) is a standard mail protocol used to receive emails from a remote server to a local email client. POP3 allows you to download email messages on your local computer and read them even when you are offline.
It's intersting to compare IMAP to POP3 ! And understand there flow better! Here a good article that do that and detailed explanation!
Now the protocol dectate no limit size! Also what about attachment! How the attachment are managed and send and handled by clients!
I can refer to this stackoverflow link
In resume:
To embed an attachment into an email we usually use Multipurpose Internet Mail Extensions (MIME) described in RFC 2045.
Basically, to send an attachment we divide our email into parts, so the first part is the text and the next part(s) is an attachment(s) or vice versa.
To see the original email structure, we can click "Show original" on an email with attachment(s).
Check the link to see an example!
Now that's how attachment are send! Part of the body! and with (MIME)! Just like http do with forms content! There is however no size limit restriction at the protocol levels!
Any size limit is set by the email server!
We can see different size limits as per the links bellow:
You can check the size array ! Gmail for example it's 25MB ! Outlook/Office 365 20 MB (10 MB for Exchange accounts), with up to 150 MB in Office 365
For attachement and all! The clients Know how to read and handle them! By text processing! And the handling of the MIME format!
Use cloud storage services (like google drive)! And include a link!
One can use google drive api! Or drop box too! Create a file there first! Get the link! Then attach the link only part of the message!
You can use the archiver
module as per here
Need to ZIP an entire directory using Node.js
(there is a code example)
After done zipping one attach the file! That may be the best way!
One should use fs.readdir() from the fs
module
https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback
https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options
Here with code examples
https://www.geeksforgeeks.org/node-js-fs-readdir-method/
Including recursion example:
https://stackoverflow.com/a/45130990/7668448
One too can use the glob
module ! And use glob notation! If glob's make it easier! (one may not need to do that and add more dependencies)
https://www.npmjs.com/package/glob
One need to use the specific api client! And follow the api instructions! For example google drive:
https://developers.google.com/drive/api/v3/quickstart/nodejs
Upload the files there! Then getting a link to it!
Which one include in the email message!