Since none of the answers speaks of the whole message with pure Ruby, here it is.
Net::SMTP.start("localhost") do |smtp| smtp.open_message_stream opts[:sender_address], opts[:receiver_address] do |f| f.puts "Content-type: text/plain; charset=UTF-8" f.puts from f.puts to f.puts subject f.puts message end end
Here you open a connection with localhost. Using an external SMTP server is also possible, see the net / smtp documentation.
The character set of the first line used in the message. The remaining lines are variables defined separately:
from is an address in the form From: Name here < address@here.fi > . If a name is not required, only the address can be specified, for example From: address@here.fi .
uses the same syntax, with the exception From: changed to To:
the subject is in the form of Subject: subject here. For UTF-8, it must be encoded in Base64 to display correctly for clients.
subject = "Subject: =?UTF-8?B?" + Base64.strict_encode64(subject) + "?="
The message is a text-to-text message encoded in UTF-8 without a prefix. net / smtp will take care of creating proper mail.
Smar
source share