Is it possible to send email from another stream like this?

On a website sending emails several times takes a few seconds, so I need to send an email from another stream so as not to wait for the message to be sent.

I found this answer in stackoverflow, is it possible to do this if I send only one request by email?

Or is there another standard way to do this?

+6
source share
2 answers

If possible, you should configure a local SMTP server that listens only for the loopback address (127.0.0.1), since this is exactly what mail queues are for. You can configure the SMTP server to relay through your real outgoing mail server so that you don’t have problems with SPF treating your mail as spam.

Thus, your application can quickly put an outgoing mail queue and be on it in a fun way, and you can be sure that the message will be delivered even in case of heavy load, network problems or even failures.

+4
source

The appearance of new threads from within the request handler is potentially dangerous: if you get a surge in traffic, you can create enough threads, which will worsen the spike.

It would be better to cancel sending mail to another process using a tool such as beanstalkd or another message queue, or use the -supplied mail system (my Linux mail(1) system mail(1) can insert an email message in 0.7 seconds, which corresponds to moderate mail loads )

Measure the amount of traffic expected. If this is an internal tool that will only be used by a few dozen people, then spawning of new streams is probably fine. If it was exposed to a big bad world, I would recommend a more reliable queuing mechanism that will have less impact on system resources.

+2
source

Source: https://habr.com/ru/post/891606/


All Articles