socket.error: [Errno 13] Permission denied when creating a fake email server

前端 未结 5 1739
深忆病人
深忆病人 2021-01-05 16:24

I\'m trying to create a fake email server as part of a Flask app to print out errors on the console by using the following script. However, it throws an error. How can I fix

相关标签:
5条回答
  • 2021-01-05 16:55

    Run the program as superuser. The smtp-port as any port <=1024 is reserved to the system and cannot be used by normal users.

    0 讨论(0)
  • 2021-01-05 17:02

    If you are doing this as an exercise, then @solarnz has the right approach. If however, you need this done for work there is a far better solution in mailcatcher:

    MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.

    This is a program designed especially for developers whose apps need a mail server for testing but they don't want to set one up.

    The great bonus is that it comes with a web interface to view messages sent by your application:

    mailcatcher web interface

    0 讨论(0)
  • 2021-01-05 17:11

    maybe SELinux cause this problem.. I solved problem through by "setenforce 0".

    0 讨论(0)
  • 2021-01-05 17:13

    In unix (Linux, Mac OS X, BSD etc) systems, ports less than 1024 can not be bound to by normal users, only the root user can bind to those ports.

    To get around this, you could run your python application as root (by using sudo), however this is not preferable. Is it possible instead to get your Flask application to talk to localhost on a higher port, say 2525? You would then need to modify the command you are using to start the smtp server to bind on port 2525 rather than 25.

    0 讨论(0)
  • 2021-01-05 17:14

    Execute program with root or sudo previliages, but as suggested above this is not recommended,

    so setup your service on port >= 1024 and then setup reverse proxy for your service, or

    redirect all traffice from port 25 to your service port,

    For example :

    /sbin/iptables -t nat -I PREROUTING -p tcp --dport 25 -j REDIRECT --to-port 2525
    
    0 讨论(0)
提交回复
热议问题