Git Product home page Git Product logo

Comments (6)

andris9 avatar andris9 commented on May 22, 2024

Streamed attachments are possible in theory but not something trivial. It is possible to use streams because attachments don't need any size or length headers in the mime body - you can add anything you want and close the attachment with the predefined boundary when the file is finished streaming.

Firstly a base64 encoder for streams is required. This is not very difficult, I have created base64 decoder which needs be reversed (encoding instead of decoding). https://gist.github.com/576480

Secondly, message body generation needs to be reimplemented, since currently it builds the whole message body as one large string but this needs to be done on the SMTP side instead. After emitting DATA command and sending the headers, mail body needs to be streamed, first text parts and then the streamed attachments.

DATA\r\n
Headers....\r\n
\r\n
----boundary-----\r\n
text
----boundary-----\r\n
html
----boundary-----\r\n
stream base64(attachment1)
----boundary-----\r\n
stream base64(attachment2)
....
----boundary-----\r\n
.

Doable but not trivial.

from nodemailer.

bvirlet avatar bvirlet commented on May 22, 2024

I'm actually trying to get nodemailer working with large attachments.
With sending to a SMTP, the bottleneck is when sending the data to the SMTP and it's getting very slow.
When using sendmail, there was an issue because the command line was too long. I tried to switch to streams and to pipe the mail into sendmail, which was also very slow. I finally decided to write the email in a file, and then I spawn "sendmail < file". This seems to be much faster. Any idea why?

from nodemailer.

andris9 avatar andris9 commented on May 22, 2024

Hi, is the SMTP server a local one or remote (gmail etc.)? I think that sendmail caches the mail file instead of sending it immediatelly and thus when the program returns then the mail is not yet sent but queued to be sent on first opportunity. But I might be wrong about it, I'm not so familiar with sendmail.

from nodemailer.

bvirlet avatar bvirlet commented on May 22, 2024

Yes you are correct regarding the queuing but actually it was putting the message in the queue which was very slow.

To summarize I had the slowness issue in the following cases:

  • Connecting to a local SMTP server (on localhost).
  • Piping into the Sendmail process (using the node.js pipe API)

It was fast when doing:

  • Writing a file to disk, then spawning Sendmail and read from that file.

from nodemailer.

bvirlet avatar bvirlet commented on May 22, 2024

Actually I implemented the faster solution here: https://github.com/bvirlet/Nodemailer/tree/large-attachments
But it's not 100% satisfying since I don't understand why it is slow in the other cases.

from nodemailer.

andris9 avatar andris9 commented on May 22, 2024

New v0.3 branch includes file streaming.

from nodemailer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.