Skip to content

Instantly share code, notes, and snippets.

@cypriss
Created August 14, 2012 17:32
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cypriss/3351043 to your computer and use it in GitHub Desktop.
Save cypriss/3351043 to your computer and use it in GitHub Desktop.
Use TMail -> Mail gem in Rails 2.3
require 'action_mailer'
require 'mail'
module ActionMailer
class Base
def clean_address(str)
EmailAddress.parse(str, :no_default_name => true).quoted rescue str
end
def create_mail
m = Mail.new
m.charset = charset
m.subject = subject
m.to = clean_address(recipients)
m.from = clean_address(from)
m.bcc = bcc unless bcc.nil?
m.cc = cc unless cc.nil?
m.reply_to = reply_to unless reply_to.nil?
m.mime_version = mime_version unless mime_version.nil?
m.date = sent_on.to_time rescue sent_on if sent_on
m.message_id = "<#{Mail.random_tag}@yourdomain.com>"
headers.each { |k, v| m[k] = v }
if @parts.empty?
raise "JonathanActionMailer: Not supported -- empty parts"
else
if String === body
raise "JonathanActionMailer: Not supported -- string body"
end
@parts.each do |p|
part = (Mail::Part === p ? p : p.to_mail(self))
m.add_part(part)
end
m.content_type(["multipart", "alternative", m.content_type_parameters])
end
@mail = m
end
end
class Part
def to_mail(defaults)
real_content_type, ctype_attrs = parse_content_type(defaults)
part = Mail::Part.new(:content_type => real_content_type, :content_disposition => "inline", :body => body, :charset => "utf-8")
raise "JonathanActionMailer: Not supported -- @parts not empty" unless @parts.empty?
raise "JonathanActionMailer: Not supported -- transfer_encoding: base64" if (transfer_encoding || "").downcase == "base64"
raise "JonathanActionMailer: Not supported -- attachments" if content_disposition == "attachment"
raise "JonathanActionMailer: Not supported -- headers on parts" if headers.any?
part
end
end
end
module Mail
class Message
def ready_to_send
nil
end
end
end
@drasch
Copy link

drasch commented Feb 15, 2013

Thanks for posting these!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment