Eventful Email in Ruby

3,160 views

Published on

Published in: Technology, Business
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
3,160
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
16
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Eventful Email in Ruby

  1. 1. Eventful Email In Ruby - Lightning Talk
  2. 2. 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
  3. 3. Catch All Aliases?
  4. 4. Really?
  5. 5. • Catch All aliases encourage spam to your server • Waste resources processing mail that should be bounced
  6. 6. What Else To Do?
  7. 7. Process Email as it Arrives
  8. 8. Postfix
  9. 9. Event Machine SMTP
  10. 10. WTF • Postfix on port 25 relaying to EM-SMTP • Postfix receives and buffers the email • Forwards it onto EM-SMTP when available
  11. 11. Setup Postfix • Setup Basics • http://articles.slicehost.com/email
  12. 12. /etc/postfix/main.cf myhostname = mydomain.com myorigin = /etc/mailname relayhost = mynetworks = 127.0.0.0/8 relay_domains = mydomain.com transport_maps = hash:/etc/postfix/transport
  13. 13. /etc/mailname mydomain.com
  14. 14. /etc/postfix/transport mydomain.com smtp:[127.0.0.1]:2525
  15. 15. Write Your EM Server class MySmtpServer < EM::Protocols::SmtpServer def initialize(*args) super @parms[:chunksize] = 1024 end
  16. 16. Specify Who Can Receive Return True for OK def receive_recipient(recipient) !!User.first(:email => recipient) end
  17. 17. 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
  18. 18. 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
  19. 19. Fire It Up EM.run { EM.start_server quot;0.0.0.0quot;, 2525, MySmtpServer }
  20. 20. More Information http://github.com/eventmachine/eventmachine Huge Thanks to Andy from Octopus Computing http://octopus.com.au/

×