From: Daniel Kelley Date: 2005-08-08T12:51:10+09:00 Subject: Re: sending an email with an attachment in ruby Matthew Margolis writes: > I would like to send email from a server running FreeBSD(TextDrive) to > my gmail account to make a weekly backup of my customer's website. The > attachment that I need to be able to send will be a tgz and will be > around 15 MBs. What are my options for constructing and sending this > mail via ruby? > I was hopting to show off something clever, but all I use is is 'metasend'. The code below isn't complete, but it should give you an idea. # # Mail the output file as an attachment # def mail(addr, subject) # no point if no address or records generated if addr.nil? || @contact.length == 0 || @can_mail == false return false end a = addr.split(",") if a.length < 1 raise "no email addresses" end args = [ "-b", "-S", "4000000", "-f", @summary_output_file, "-m", "Text/Plain; charset=us-ascii", "-n", "-f", @csv_output_file, "-m", "application/octet-stream; name=\"#{@csv_output_file}\"", "-D", @csv_output_file, "-s", format_timestr(subject), "-t", a[0] ] if a.length > 1 args << "-c" args << a[1..-1].join(",") end system("metasend", *args) end Pretty boring. But it has worked since February of 2004. d.k. -- Daniel Kelley - San Jose, CA For email, replace the first dot in the domain with an at.