I have a live site, but would like to run a periodic task that would periodically check if various pages and email sending work.
e.g. register page, forgot password page, etc...
I'm having quite a problem figuring out how to do this...
Any ideas? :)
At my workplace we use nagios to monitor, among many things, that the smtp service and web apps are running as it should. For crucial pages, we use the check_http nagios plugin to ensure that the pages are accessible and contain specific keywords.
You can set each check to run as frequently as you like, and have nagios send you an email if anything goes amiss.
As for checking whether email sending from django is working, that's a little tricky. None of my sites are mission critical, so I'm happy to assume that if my code base doesn't change and if the web apps and SMTP servers are working, then emails from django should be ok.
If it is critical that you check that django can send emails, you could have a view (restricted by source IP and perhaps a password in POST/GET) that triggers an outgoing email. You can then write your own plugin to access said view and check that the email is sent.
Here's a nice write-up on how to check your email service using nagios: http://www.linuxjournal.com/content/monitoring-email-nagios
Related
I have just integrated Stripe Checkout with my Django app. However, from their code:
session = stripe.checkout.Session.create(
customer_email=customer.email,
payment_method_types=['card'],
line_items=line_items,
mode='payment',
success_url='http://127.0.0.1:8000/SUCCESS/?session_id={CHECKOUT_SESSION_ID}',
cancel_url='http://127.0.0.1:8000/cart'
)
It redirects to a Success_url. I would like to display their order info and send an email from the success page but currently, everyone can visit(would cause random emails etc). Is there a way i can limit this for the person that just checked out? Thank you!
The success page should really just be a page to let your users know that their payment went through. I wouldn't personally recommend triggering any app-specific logic when your users land on it. As you've pointed out this could cause accidents with users randomly stumbling on that page and triggering emails. It also offers an opportunity for bad actors to exploit your application.
Instead, I would create a webhook endpoint and listen for the checkout.session.completed event, and trigger your emails from there. Building a webhook endpoint should be no more difficult than building any other endpoint on your server, with there only being some small extra logic to verify incoming requests.
Another option would be to use a tool like Zapier to listen for these events from Stripe and trigger various flows from them: https://stripe.com/partners/zapier
I'm using django-sendgrid-v5 and I read somewhere that it isn't good to send emails from the main webserver. Should I process emails from Celery? Or is it fine to call from the main app since I'm using an external service like Sendgrid anyways?
I don't know in which context you've read that, but I would guess it has something to do with reliability, spam and security in general.
Short answer: Yes, this should be fully okay as you are using an external email service.
Another option is to set up a Smart host on your webserver and let your main email server deliver it to the final recipients.
Long answer: Nowadays sending emails from a (web)server, which is not fully set up as an email server might be difficult in means of reliably sending emails.
Due to the massive amounts of spam and malware sent, most (or at least a lot) receiving email servers (Mail Exchangers) are trying to check if the emails they should deliver to their users, are legit.
This is done by several settings mostly on the server itself. To name only a few: RDNS, DKIM, Greylisting, etc.
In general a (web) server whos main purpose is not sending emails, does not have all these settings. This might result in difficulties to reach certain email addresses.
I am setting up a GAE app that triggers certain tasks by an email from the user. I've set up the app using the information on this page: https://developers.google.com/appengine/docs/python/mail/receivingmail. Everything works as expected, however, I would like to send the emails to a #mydomain.com email address, instead of a #myapp.appspotmail.com email address.
Currently I am using an automatic forward on the email address to get around this, however once this scales I expect to reach the daily limit on forwarded messages at some point (10.000 according to https://support.google.com/a/answer/166852?hl=en).
Is there any way that I can integrate my app with the #mydomain.com email address to prevent this from happening? Or would you know another solution for this issue?
Probably, you should check recently implemented GAE integration with SendGrid, I haven't used it myself (use the same solution you've described with email forwarding), but looks like it can help.
As LA_ mentioned, SendGrid offers a webhook for this. I ended up using MailGun, which has a similar functionality and calls a HTTP POST to my app whenever an email comes in on my #mydomain.com address.
I'm looking for a mail server that I can completely control from Python/Django. When I say "completely control", I'm just talking about basic administrative tasks like: (1)setting up new accounts, (2)changing account passwords, (3) setting / changing email forwarding, and perhaps some other basic account settings.
To be specific, my questions are: Which mail server is best for this? Which mail servers have APIs that are most comprehensive?
i've never used lamson, but it's worth taking a look at it.
http://lamsonproject.org/ it seems interesting for several reasons.
but in general, you can easily build a wrapper around any mail server that has commandline tools for configuration, and any mail server that can store users and aliases in a database, would make mail server configuration as easy as doing an inspectdb and adding the correct logic for password creation, etc...
I was wondering if someone could help me out. In some web application, the app will send out emails, say when a new message has been posted. Then instead of signing into the application to post a reply you can just simply reply to the email and it will automatically update the web app with your response.
My question is, how is this done and what is it called?
Thanks
Generally:
1) Set up a dedicated email account for the purpose.
2) Have a programm monitor the mailbox (let's say fetchmail, since that's what I do).
3) When an email arrives at the account, fetchmail downloads the email, writes it to disk, and calls script or program you have written with the email file as an argument.
4) Your script or program parses the email and takes an appropriate action.
The part that's usually mysterious to people is the fetchmail part (#2).
Specifically on Mail Servers (iff you control the mailserver enough to redirect emails to scripts):
1-3) Configure an address to be piped to a script you have written.
4) Same as above.
You should take a look at Lamson; it'll enable you do what you've described, and more besides.
From your tags, I'll assume you're wanting to do this in Django.
There's an app out there called jutda-helpdesk that does exactly what you're looking for using poplib, which means you just have to set up a POP3 compatible email address.
Take a look at their get_email.py to see how they do it. You just run this script from cron.
This is an area where the Rails-world is ahead: Rails has built-in support for receiving emails. The mail sever configuration though is probably just the same.
To see a working example on how to receive emails in python and process then using django, check this: http://code.google.com/p/jutda-helpdesk/
A common tool used for this purpose is procmail.
You need to set up dedicated email address (which is the "from_email" address in your outgoing email). Then your MTA, such as postfix or qmail, will deliver mail to that address to procmail instead of an actual mailbox.
Procmail can then pass the email on to your python script that can do updates in the app. See standalone django scripts by James Bennett on how to code python scripts that can work with your app.