From: Dave Baldwin Date: 2008-09-04T16:22:37+09:00 Subject: Re: Send email with attachments in Ruby On 3 Sep 2008, at 18:09, loominator1970 wrote: > I'm trying to find some code to send an email with attachment in > ruby. I'm using the following code to send an email, but I would like > to send an PDF. Can someone please tell me what code i need to add to > include a file called "the_attachment.pdf"? Thanks, Dave I use this: require 'rubygems' require 'action_mailer' require 'mime/types' ActionMailer::Base.smtp_settings = { :address => '10.209.3.26', :domain => '3dlabs.com'} class Mailer < ActionMailer::Base def message (title, body) from 'Dave Baldwin ' recipients 'dave.baldwin@3dlabs.com' 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') Dave.