Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:07:51+00:00 2026-05-26T05:07:51+00:00

I’m currently working on a quite small project. I’m basing my work on smtpd.py

  • 0

I’m currently working on a quite small project. I’m basing my work on smtpd.py but slowly moving toward something completely different.

This is a smtp server. It currently receive and can relay mails. It’s pretty straight forwards but I reached a point where i’m asking myself some questions.

smtpd.py use asyncore and asychat. The problem is that it is a single process using an async api. Everything works and I can go further without much problems.

The problem is that if the server is binded on port 25 it must be under the root uid. So here is the big problem. The idea behind the smtp server is that I can implement lots of things using python. I want to be able to access local users, databases or any data store possible. From hashes or anything currently supported by python or I can even add support for it if needed.

The thing is that I feel that having all this control using the root user is very unsecure… what if someone can do something and well endup with a root python shell…

So at first I wanted to create threads and set them a different uid using os.setuid but it doesn’t seems to work or can be dangerous too.

My second idea: Accept connection then fork and change uid. I should be able to write/read the socket from the forked process and all should be fine.

The third idea was to have a proxy server that relay all messages to a local server that will himself handle the messages. The only problem with that is that if someone that isn’t supposed to use my smtp server the proxy cannot auth or do anything since it’s just a proxy with no actual access to anything.

I believe the fork is the most interesting solution.

Or may be there is something I haven’t tought of yet.

Anyway thanks

–Edit–

Apparently if the process is started with root and once the socket is created, it is possible to switch to a different user using os.setuid. I guess it’s not really portable but that’s not a big problem for now. After searching trough the codes of Pyramid/Pylons/Paste I finally came accross that thing! The SocketServer module. And I’m probably going to use either ForkingMixIn or ThredingMixIn. It is possible to define the amount of threads etc.

In any case, for people who are wondering why I’m not using postfix, exim or qmail.. It is quite simple, I’m not really making a smtp server. The smtp protocole is pretty simple if you only implement the minimum required which is receiving emails, accepting or refusing recipient or sender etc.. Escaping the first “.” of each new line because the RFC says that data ends with “\r\n.\r\n”.

As I see it, python is more like building blocks. The idea isn’t to make a smtp server (well I will surely implement ESMTP) but to make a “framework” to build your own server. The problem I have and I don’t believe that I’m alone. Someone designed a config file and a way to configure postfix. It’s hardcoded and doesn’t fit all case. Making a server that fit all case isn’t going to work either. It would probably get huge and ugly. The idea is to make it easy to adds parts you want on your server. If you want to use a database use the one you want with an existing module. Do your query and send back your results.

If you really want to define rules that apply to all domains or to certain domains or even usernames it should be possible to do.

I, for example, see a use case. Really strange one but still. How easy would it be to setup that kind of setup on postfix using only one server. You have three domain. a.com, b.com, c.com.

a.com send all received mail to a maildir and to b.com with the same username.
b.com send all received mail to a maildir and to c.com with the same username.
c.com send all received mail to a maildir and to a.com with the same username.

No domain accept email that they already sent.

In other words

           a.com -> b.com -> c.com -x-> a.com
           b.com -> c.com -> a.com -x-> b.com
           ... 

The idea here is that the mail will get replicated accross multiple domains but it cannot get back to its owner. That kind of use case should be pretty simple. but what if all domain saves their mail in different locations or we want to save the mail every 2 bounce.

 a -> b -> c(save)
 a -> b(save) -> c
 a(save) -> b -> c
 already saved to C so stop the mail would be sent 9 times 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:07:52+00:00Added an answer on May 26, 2026 at 5:07 am

    The answer to the question is to use ServerSocket. I’m going to use either the threading or forking subclass. It is quite flexible and can replace asyncore without fear. It is already being used by pylons, pyramid etc. But in my case it will handle smtp messages instead of http.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.