Guest User

Untitled

a guest
Jun 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. require 'rubygems'
  2. require 'action_mailer'
  3. require 'mime/types'
  4.  
  5. ActionMailer::Base.smtp_settings = { :address => '127.0.0.1', :domain => 'kmssoftware.co.nz'}
  6.  
  7. class Mailer < ActionMailer::Base
  8. def message (title, body)
  9. from 'John Jansen <john.jansen@...>'
  10. recipients 'john.jansen@...'
  11. subject title
  12. body body
  13.  
  14. # Include all the pdf files in the PDF subdirectory as attachments.
  15. FileList['PDF/*.pdf'].each do |path|
  16. file = File.basename(path)
  17. mime_type = MIME::Types.of(file).first
  18. content_type = mime_type ? mime_type.content_type : 'application/binary'
  19. attachment (content_type) do |a|
  20. a.body = File.read(path)
  21. a.filename = file
  22. a.transfer_encoding = 'quoted-printable' if content_type =~ /^text\//
  23. end
  24. end
  25. end
  26. end
  27.  
  28. Mailer.deliver_message('some title', 'the body message')
Add Comment
Please, Sign In to add comment