PDA

View Full Version : SMTP server for dev work



ericpierce
September 12th, 2010, 03:58 AM
Hi all,

I'm looking for an SMTP server for dev work under Linux. I've searched the forums and didn't quite find the answer I was looking for.

I recently ran across a cool open source project called smtp4dev (Windows/.NET). It is basically a dummy SMTP server
where you can view all emails (regardless of email address domain) sent to it w/o them actually being sent on to the outside world. It's a very cool app, and I use it at my day job (on WinXP). However, it doesn't compile in Mono.

I wondered if there wasn't already an app like this
for Linux. Or maybe Sendmail or Postfix could be configured to serve this purpose (i.e., dead end SMTP server). I have
zero experience in either of them, so smtp4dev has a lot of appeal because of its ease of set up and use.

smtp4dev
http://smtp4dev.codeplex.com/

Anyway, just looking for some ideas for doing the same under Linux.

Thanks for reading,
Eric P.

DanielWaterworth
September 12th, 2010, 10:11 AM
try this in python:


import smtpd, asyncore

server = smtpd.DebuggingServer(('localhost', 8000), None)
asyncore.loop()

ericpierce
September 16th, 2010, 04:13 AM
I've never used Python before.

Can you explain what that code does?

Does it possibly capture all outgoing emails and store them somewhere for inspection?

Thanks,
Eric P.

slavik
September 16th, 2010, 08:27 AM
smtp servers STORE mail. :)

easy fake smtp server in shell (make sure netcat is installed)


sudo nc -l -k 25 &> /tmp/nc.log

DanielWaterworth
September 16th, 2010, 08:30 AM
It should send all emails that you send to it to stdout, ie the console. If you want to log emails to a file as well, pipe the output through tee ( http://en.wikipedia.org/wiki/Tee_%28command%29 ). It starts the email server on port 8000, if it's more convenient to use a different one then just change the number in the source. It's also bound to localhost, which means it may not be possible to send it emails from other computers, if you'd like to send it emails from other computers then replace 'localhost' with '' in the source.

You can test that it works with this:


import smtplib

s = smtplib.SMTP('localhost', 8000)
s.sendmail(['test'], 'test', 'test')

ericpierce
September 17th, 2010, 05:11 AM
It should send all emails that you send to it to stdout, ie the console. If you want to log emails to a file as well, pipe the output through tee ( http://en.wikipedia.org/wiki/Tee_%28command%29 ). It starts the email server on port 8000, if it's more convenient to use a different one then just change the number in the source. It's also bound to localhost, which means it may not be possible to send it emails from other computers, if you'd like to send it emails from other computers then replace 'localhost' with '' in the source.

You can test that it works with this:


import smtplib

s = smtplib.SMTP('localhost', 8000)
s.sendmail(['test'], 'test', 'test')

Daniel,

I got the DebuggingServer working on port 25, and some Java code I wrote is able to send emails to it. Very, very cool! =D>

The only issue I have now is some of my emails contain Japanese text, and it shows up as a jumble of unrecognizable English letters/numbers. Is there something w/Python to show UTF-8 characters in their native character set? I know the Japanese characters are being sent correctly because they were showing up when I was sending email to a Windows box running smtp4dev.

slavik, I didn't have any luck w/the netcat line you provided. I'm not sure how that could work as an SMTP server since I believe a real SMTP server needs to communicate back to the client. Anyway, it didn't work w/my code nor the Python email sender code Daniel provided.

Thanks both of you for your ideas. I've been looking for a solution for this for months! Just need to get the Japanese char issue sorted.

Sincerely,
Eric P.

endotherm
September 17th, 2010, 05:15 AM
this maybe of help:
http://evanjones.ca/python-utf8.html

DanielWaterworth
September 17th, 2010, 09:02 AM
First off, to test the system, this:


# encoding: utf-8
import smtplib
from email.MIMEText import MIMEText

body = u"こんにちは".encode("EUC-JP")

msg = MIMEText(body, 'plain', 'EUC-JP')

smtp = smtplib.SMTP("localhost", 25)
smtp.sendmail('test', ['test'], msg.as_string())
smtp.quit()should send Japanese emails to the debugging server. When I send emails using the above script, they are printed and readable (well, readable to someone who understands Japanese). I think that your problem is with the locale of the console your sending them to. Please try sending the output to a file with something like this.


python email_server.py > unicode_testIf this works then try adding:


export LC_ALL=Cto your .bashrc file.

Disclaimer: I'm no expert in bash or locale settings, please correct me if I'm wrong.

DanielWaterworth
September 19th, 2010, 08:57 AM
@Eric: have you made any progress on this?

ericpierce
April 30th, 2011, 05:20 AM
@Eric: have you made any progress on this?

Hi Dan,

Just getting back to this problem. I believe I found a workable solution.

For starters I found a slightly more robust Python script to act as a dummy SMTP server. It dumps the incoming email into an email file w/header, etc. in tact.

Here's the script.
http://www.linux-support.com/cms/component/content/article/181-dummy-smtp-server-in-python

When emails are sent to and saved by the dummy SMTP server script, I can open them in Thunderbird and the Japanese/UTF-8 text is appearing as it should.

I'd like to tweak the script so that the email files are created within a Thunderbird folder with the hope that the emails would just show up in that folder real time as they're created and it'd just be one click to view its content. But I haven't been able to get that to work just yet.

Anyway, thanks for everyone's help and sorry I abandoned the thread for this long. Hope someone else finds this info as helpful as I did!

Eric P.