Should I put emails in the database before sending, and not on the fly?

I am developing a site that sends email notifications to users after certain events / user actions (marked in photos, added as friend, etc.).

In my experience, sending emails from a web server can be slow. For example, when creating a new user, I will send an email to confirm / greet the account. However, there is a slight pause, sometimes waiting for the page to load while it finishes sending the email.

My fear is that if I ever have a problem connecting to my mail server or mail server, it will make it difficult to load my application / page

So my question is: what's the best way to send emails from a web application that sends emails on an ongoing basis?

Do I have to create a queue system by storing the contents of the email in the database, and then run the scheduled cron jobs to process all the received emails?

Or do I just need to send an email right after a user completes an action / event (creating a member account marked in the photo, etc.)?

+3
source share
5 answers

No. Ask your sysadmin to configure the mail server. A properly configured mail server should be faster than storing messages in a database.

, . [ ] sendmail_path =/usr/sbin/sendmail php.ini

, ( ).

+2

. , , . , , .

+2

, , mysql, , cron x , ( LIMIT sql, ).

0

, -/ - , , - . , . , async.

In this case, the advantage of storing your sent messages in a database (or in some other store) - unlike the queue in the memory queue - is that you have more recovery options in the event of a failure of your web server. You can always process the stored messages later, but if you have them in memory, any failure of your web server will mean the loss of mail messages.

0
source

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


All Articles