Skip to content

Instantly share code, notes, and snippets.

@radiospiel
Created October 26, 2016 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radiospiel/e634134c5785ae84a56ca7140966ac62 to your computer and use it in GitHub Desktop.
Save radiospiel/e634134c5785ae84a56ca7140966ac62 to your computer and use it in GitHub Desktop.
require "mail"
mail = Mail.new do
to 'nicolas@test.lindsaar.net.au'
from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
subject 'First multipart email sent with Mail'
end
text = 'Find my source code attached'
html = 'Find my <b>source code</b> attached'
html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body html
end
text_part = Mail::Part.new do
body text
end
mail.part :content_type => "multipart/alternative" do |p|
p.html_part = html_part
p.text_part = text_part
end
mail.attachments['some.rb'] = { content: File.read(__FILE__), mime_type: "text/ruby" }
# Don't know if this is really necessary:
#
# mail.content_type = mail.content_type.gsub('alternative', 'mixed')
# mail.charset= 'UTF-8'
# mail.content_transfer_encoding = 'quoted-printable'
puts mail.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment