Email Processing I’ve
Seen
• Sometimes done with a catch all alias on
the mail server
• Store emails as files on disk
• Implement a file scanner to read and
process messages
Catch All Aliases?
Really?
• Catch All aliases encourage spam to your
server
• Waste resources processing mail that
should be bounced
What Else To Do?
Process Email as it
Arrives
Postfix
Event Machine SMTP
WTF
• Postfix on port 25 relaying to EM-SMTP
• Postfix receives and buffers the email
• Forwards it onto EM-SMTP when available
Write Your EM Server
class MySmtpServer < EM::Protocols::SmtpServer
def initialize(*args)
super
@parms[:chunksize] = 1024
end
Specify Who Can
Receive
Return True for OK
def receive_recipient(recipient)
!!User.first(:email => recipient)
end
Tell It What to Do
def receive_data_chunk(data)
# Do stuff with data
# collect it in an ivar
# collect in a file
true
end
Once The Message Is
Complete
def receive_message
# Do Stuff if you’ve collected in an ivar
# Or sent to a file
# Clear ivar
true # false rejects message
end
Fire It Up
EM.run {
EM.start_server \"0.0.0.0\", 2525, MySmtpServer
}
More Information
http://github.com/eventmachine/eventmachine
Huge Thanks to Andy from Octopus Computing
http://octopus.com.au/
0 comments
Post a comment