Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example from README does not work as-is - syntax error #30

Open
emanuil-tolev opened this issue Jan 7, 2016 · 4 comments
Open

example from README does not work as-is - syntax error #30

emanuil-tolev opened this issue Jan 7, 2016 · 4 comments

Comments

@emanuil-tolev
Copy link

(fosdem-volunteers)emanuil@midori:~/software/secure-smtpd$ python --version
Python 2.7.6

(fosdem-volunteers)emanuil@midori:~/software/secure-smtpd$ pip freeze | grep smtpd
secure-smtpd==3.0.0

(fosdem-volunteers)emanuil@midori:~/software/secure-smtpd$ cat run.py 
from secure_smtpd import SMTPServer, FakeCredentialValidator
SMTPServer(
self,
('0.0.0.0', 465),
None,
require_authentication=True,
ssl=True,
certfile='examples/server.crt',
keyfile='examples/server.key',
credential_validator=FakeCredentialValidator(),
)
asyncore.loop()

(fosdem-volunteers)emanuil@midori:~/software/secure-smtpd$ python run.py                                                                                                                
Traceback (most recent call last):                                                                                                                                                      
  File "run.py", line 3, in <module>                                                                                                                                                    
    self,                                                                                                                                                                               
NameError: name 'self' is not defined
@emanuil-tolev
Copy link
Author

Ah, googled around and found your blog post: http://bencoe.tumblr.com/post/12753680108/writing-a-secure-smtp-server-in-python

There is actually a problem with the code in there too - seems like the debug keyword argument was removed from SMTPServer's constructor at some point, so that also gives a syntax error. Removing the debug=true arg from your blog post code seems to run it though (will test if working now). Might be worth including the snippet below in the README and therefore in PyPI - I'll make a PR after confirming it actually works as well.

The final code I used to run it was

import asyncore
from secure_smtpd import SMTPServer, FakeCredentialValidator

class SSLSMTPServer(SMTPServer):

    def __init__(self):
        pass

    def process_message(self, peer, mailfrom, rcpttos, message_data):
        print message_data

    def start(self):
        SMTPServer.__init__(
            self,
            ('0.0.0.0', 25465),  # note if you want to run it on the default port 465 for secure SSL SMTP you will need sudo rights as all ports below 1024 are privileged
            None,
            require_authentication=True,
            ssl=True,
            certfile='examples/server.crt',
            keyfile='examples/server.key',
            credential_validator=FakeCredentialValidator(),
        )
        asyncore.loop()

server = SSLSMTPServer()
server.start()

@emanuil-tolev
Copy link
Author

When an app tries to initiate a connection to that port, I just get

_accept_subprocess(): smtp connection accepted within subprocess.

and it dies immediately, no leftover python processes running secure-smtpd. Tried setting maximum_execution_time to 600 as well, but still did it (besides, I tried within 30 seconds of running it anyway). I'm looking to just dump the emails to stdout - basically I'd like to have a local secure SMTP running as the app expects one to be configured or it errors out.

Anyway, if there is something else I should modify in the run.py example to get better results, let me know - otherwise I'll wait a bit and submit a PR to update the README so we have a runnable copy/pastable example :).

@bcoe
Copy link
Owner

bcoe commented Jan 9, 2016

@emanuil-tolev I would love your update to the README. I unfortunately am not writing too much Python anymore, and I've been relying on the community to keep my old Python projects is a healthy state -- greatly appreciate your debugging.

@thijstriemstra
Copy link

Probably a different issue, but all I see is:

  File "/Users/foo/bar/src/secure-smtpd/secure_smtpd/smtp_channel.py", line 9, in <module>
    from smtpd import NEWLINE, EMPTYSTRING
ImportError: cannot import name 'EMPTYSTRING'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants