Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'action_mailer'
- require 'mime/types'
- ActionMailer::Base.smtp_settings = { :address => '127.0.0.1', :domain => 'kmssoftware.co.nz'}
- class Mailer < ActionMailer::Base
- def message (title, body)
- from 'John Jansen <john.jansen@...>'
- recipients 'john.jansen@...'
- subject title
- body body
- # Include all the pdf files in the PDF subdirectory as attachments.
- FileList['PDF/*.pdf'].each do |path|
- file = File.basename(path)
- mime_type = MIME::Types.of(file).first
- content_type = mime_type ? mime_type.content_type : 'application/binary'
- attachment (content_type) do |a|
- a.body = File.read(path)
- a.filename = file
- a.transfer_encoding = 'quoted-printable' if content_type =~ /^text\//
- end
- end
- end
- end
- Mailer.deliver_message('some title', 'the body message')
Add Comment
Please, Sign In to add comment