Which mail server can I control from Python / Django? - python

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...

Related

Django: Should sendgrid emails always be sent from Celery?

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.

How can I send mail via Python on Yosemite... without an outside server?

I have set up an unused Macbook Pro as a shared server on our internal company intranet. I'm kind of running it as a skunkworks; it can access the internet, but doesn't have permission to access, say, Gmail via SMTP. It's also unlikely to get that access anytime soon.
I'd like to be able to run processes on the machine that send notification emails. Every library I can find seems to require an email server, and I can't access one.
Is there any way to set up my MBP to act as its own email server? Thanks.
adding this an answer cause not enough space in comments.
It might work, but highly unlikely, and if you can send outbound mail, it will most likely be spam folder'd or dropped. The reason most apps use a dedicated mail server or smart host is that there are lots of other things that need to be setup besides the mail server (DNS records, SPF, DKIM,etc..). By default it if type sendmail user#example.com on your mac, type your message and end it with a . on a line by itself you mac will try to deliver it using its internal server(postfix). It will look up the Right Hand Side, look for MX records, try to connect to port 25 on the lowest order mx, and do all the things that a mail server does when delivering email. But if your skunk work project cannot access gmail on port 465 or 587 due to firewall settings, then there is very little chance that your mail admins will allow it to connect to random servers on port 25 (since this is exactly what Direct to MX Bots/Malware do).
You best bet is to contact your admins and tell them you have an application that needs to send email, (low volume, notification type, whatever), and ask them if they have an approved server that you can smart host via.
Going around network security, even with the best of intentions, is generally a bad idea. Since the rules are generally put in place for a reason

Client authorization with python backend

I'm writing panel for administrating nginx (domains, rewrites, etc), svn and other services. For that, i'm writing backend that will work on root (to change nginx configs, reload them, change user passwords, etc), and client (console client, and web app).
App works on unix sockets, and i made very simple protocol for it:
\0\0\0\0user\0key\0module\0command\0data\0
Well, this is quite simple. Client sends command and data to backend, fox ex:
\0\0\0\0morsik\0\0nginx\0add_domain\0www.domain.tld something\0
Problem is, how to authenticate that user is really morsik? For web interface i don't have to - web page have it's own authorization so i can sent some key that will work for every user that nobody will know.
Problem is if somebody have access to ssh. Then he could write simple client that will spoof username and then he could change other user configuration.
So, how can i made correct authorization for users?
Don't reinvent the wheel. ;) I found this discussion enlightening:
http://cyberelk.net/tim/2007/03/08/cups-unix-domain-sockets-authentication/ Explains the concept of socket auth.
http://pythonic.pocoo.org/2007/7/7/unix-socket-credentials-with-python Helpful details.
http://atlee.ca/software/pam/ This might work also, though less convenient.
Create a group for app admins only, etc.

Writing an email sending program in Python

I want to write an email sending script in Python. Most email programs have to connect to existing servers, like Gmail or Hotmail. I want my script to work independantly of those servers and just be able to send email itself (without having to logon anywhere else). The reason for this is because most email servers (like Yahoo) limit what you can do, such as controlling the sender address or sending certain types of files. So I wanted to write my own script to get around that. So what do I do? Where do I begin learning how to do this? Do I have to write my own server? If I do, how is that done?
You need an MTA (a.k.a. mail transfer agent), whether it's local or remote. SMTP servers talk to each other to deliver the mail through — if you don't want to connect to the remote one, you need to run a local one. Look into Postfix or exim — just be careful not to allow random people to connect to it. Go to Server Fault if you need help with configuring them.
This is language-agnostic, BTW.
The email-module of Python should give you a good starting point. Btw this was the first hit when googling Python email.
You'll essentially need to set up your own mail server. I prefer postfix but there are several alternatives, you'll have to google this one.
Once you can send email through your own server, look into smtplib or email-library for sending email with Python

Testing email sending? - Python/Django

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

Categories

Resources