The following example uses the data stream to compose a message. The data stream is a way of appending data to the end of a Ruby file and reading it using the DATA IO object. The DATA IO object is just like any of the other IO objects such as STDIN, STDOUT or an object returned by File.open. Calling DATA.read will read everything after the __END__ keyword into a string.
#!/usr/bin/env ruby require 'net/smtp' Net::SMTP.start( 'mail.isp.com', 25, 'isp.com' ) do|smtp| message = DATA.read smtp.send_message( message, 'email@example.com', 'firstname.lastname@example.org' ) smtp.finish end __END__ From: email@example.com To: firstname.lastname@example.org Subject: This is a message sent by Ruby! This is the body of the message. It can be as long as you like.