0

I want to create an automatic script in python that will inform me with an email when a new order is placed on my website. So far, I found I can use cronjobs from the apache server every minute, but it seems to be overkill since I don't get orders every minute.

So I'm looking for a better solution.

4
  • 1
    You can set the cronjob to be every 30 minutes, 1 hours, or whatever you want. Commented Oct 26, 2021 at 11:19
  • Thank you. but as i said it seems to be over kill. I need the script to run everytime that there is a new web order. Commented Oct 26, 2021 at 11:27
  • I strongly recommend celery Commented Oct 26, 2021 at 11:38
  • @wakeZheng Thank you i will check it out. Commented Oct 26, 2021 at 11:41

1 Answer 1

1

Here’s the code you can call this code whenever the order is placed by the user you don’t need to automate

If you are using django you can use this:

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

Without django you can use this :

import smtplib

sender = '[email protected]'
receivers = ['[email protected]']

message = “This is a test e-mail message."

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.