1. Computing

How to Send Email with Ruby

By

A "heredoc" is a way of making multi-line strings easy to type. It's possible to form multi-line strings with the string concatenation operator (such as "string1" + "string2"), but this operation is slow and inefficient and it adds extra syntax to every line as well. The heredoc syntax starts with something that looks like this: <<END. This means every line after this one will be part of a string, not a Ruby program. END on a line by itself will end the multi-line string. You can use any other identifier instead of END if you want, but END is the common convention.

 #!/usr/bin/env ruby
 require 'net/smtp'
 
 Net::SMTP.start(
   'mail.isp.com',
   25,
   'isp.com'
 ) do|smtp|
 
   message = <
  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. Using Heredocs

©2014 About.com. All rights reserved.