R
R
Ruslan Ezhgurov2016-08-03 13:51:00
Django
Ruslan Ezhgurov, 2016-08-03 13:51:00

How to send an email 5 minutes after return?

There is a function that sends a letter and returns True. You need to return True and send an email after 5 minutes. Hung up on threading.Timer checked prints, the letter sends at once, and displays prints on time. Then I tried to create a generator to send a letter and call the generator in time, but the result is the same. Maybe I didn't use yield correctly? Tell me how to do it better

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Kuzmichev, 2016-08-03
@Oyaseo

In bare Dzhang, the delayed sending of a letter as part of the processing of an http request seems to me to be very crutch, in any case, it is necessary to delegate the sending of a letter in some way to an external service.
If the letter is sent using some service (and not just SMTP) - for sure, its API has the possibility of delayed sending.
If Celery is used, the countdown option will help.
UPD:
Ruslan Ezhgurov: When none of the above is used. Celery is usually more difficult to integrate with a project, so start sending mail through some service. From the last good one, with which I myself worked - SparkPost, for small and medium-sized projects, free limits are enough for the eyes. At the same time, solve the problems with the delivery / distrust of mail services to you (well, you won’t spam yourself, otherwise the sparkpost itself will cut you off quickly).
Library for integration with Python/Django python-sparkpost , in the method of sending a message there is the possibility of delayed sending (see parameter start_time)

G
GavriKos, 2016-08-03
@GavriKos

How can you answer questions about the misuse of a method without seeing the actual use?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question