require 'time' require 'pathname' require 'enumerator' unless 'String'.respond_to?(:enum_for) module Mailit # = Overview: # # A simple to use class to generate RFC compliant MIME email. # # MailIt is a fork of MailFactory and provides a mostly identical API but has # been cleaned up, simplified, and made compliant to common Ruby idioms. # # Copyright (c) 2005-2008 David Powers. # Copyright (c) 2009 Michael Fellinger. # # This program is free software. You can re-distribute and/or # modify this program under the same terms as Ruby itself. # # = Usage: # # require 'net/smtp' # require 'mailit' # # mail = Mailit::Mail.new # mail.to = 'test@test.com' # mail.from = 'sender@sender.com' # mail.subject 'Here are some files for you!' # mail.text = 'This is what people with plain text mail readers will see' # mail.html = "A little something special for people with HTML readers' # mail.attach('/etc/fstab') # mail.attach('/home/manveru/.vimrc') # # server = 'smtp1.testmailer.com' # port = 25 # domain = 'mail.from.domain' # password = 'foo' # # Net::SMTP.start(server, port, domain, mail.from, password, :cram_md5) do |smtp| # smtp.send_message(mail.to_s, mail.from, mail.to) # end # # = Todo: # # * MailFactory has a method_missing that handles getting and setting of # arbitrary headers. # I went for the less magical #[] and #[]= methods. # Maybe someone can add the MailFactory behaviour. class Mail VERSION = '2009.03.02' BOUNDARY_CHARS = [*'a'..'z'] + [*'A'..'Z'] + [*'0'..'9'] + ['.', '_'] BOUNDARY_PREFIX = "----=_NextPart_" # body_boundary, encoding BODY_BOUNDARY = "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s" # attachment_boundary, mimetype, filename, filename ATTACHMENT_BOUNDARY = "--%s\r\nContent-Type: %s; name=%p\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: inline; filename=%p" HTML_BODY = <