python - How to do scheduled sending of email with django-mailer -


I am creating a dynamic app for which to be able to create email and then send them at a certain time. I was thinking that I could use the Degenego-Mailer to put things in and I can send it back. However, theire is listed in the sample case list, this is the list that it is a feature, I can not know how to do it.

What should I need to be able to set the 'when_send' field in django's message model -mailer, and when cron jobs fire the send_mail function, those people are required to filter Who has the date 'when_to_seend' which is more than the current time ...

  def send_all (): "" "Quit all eligible messages in queue." "Lock = file lock (" send_mail ") logging. Debug (" get lock ... "): lock.acquire (LOCK_WAIT_TIMEOUT) has already been left: logging.debug (except" locktimeout " Excluding the return, "Lock is already locked.") After returning: Logging. Debug ("Waiting for lock timing out. Waiting.") Return logging. Debug ("acquired.") Start_time = time.time () Dont_send = 0 deferred = 0 sent = 0 Try: In priority message (): if DontSendEntry.objects.has_address (message.to_ad) costume): logging.in Fo ("Do not send email to list% message"% message.to_address) MessageLog.objects.log (message, 2) # @@ @ Avoid verbatim result code message .delete () Dont_send + = else else: try : Logging.info ("Message sending"% s "to% s (message.subject.encode (" utf-8 "), message.to_address.encode (" utf-8 "))) core_sand_mail (message Message, message. Message_bone, message.from_resress, [message.to_address]) Avoid using MessageLog.objects.log (Message, 1) # @@@, Verbatim Result Code Message .delete () Sent + = 1 Except (Socket_error, smtplib.SMTPSenderRefused, smtplib.SMTPRecipientsRefused, smtplib.SMTPAuthenticationError), error Message: message.defer () logging.info ("postponed due to message failure:% s"% err) MessageLog.objects.lo G (message, 3, log_message = str (mistake)) # @@@, Verbatim result code Avoid deferred + = 1 at the end: logging. Debug ("issuance lock ...") lock.release () logging.debug ("released. "Logging.info (" ") logging.info ("% s Sent;% S Sent;% S Not Sent "% (Sent, deferred, dont_send)) logging.info (" done in% .2f seconds " % (Time.time () - start_time))  

For anyone to see how to customize this function to send an email to this message, where the message is. The same_send field The current time is more than that?

You just have your message processing loop (you have a date at the top of your file Time needs to be imported You can add another section to the conditions under:

  In the priority message (): If DontSendEntry.objects.has_address (message.to_address): logging.info ("email to% s Do not send the list except "% message.to_address" MessageLog.objects.log (message, 2) # @@ @ Verbatim results code message .delete () dont_send + = 1 Avoid using alif messages.Datetime.datetime.now (): Other Continue: Try: ... your other code ...  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -