File: test.rb

package info (click to toggle)
ruby-mime 0.4.4-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 284 kB
  • sloc: ruby: 1,187; xml: 17; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'mime'
include MIME   # allow ommision of "MIME::" namespace in examples below

msg = Mail.new    # blank message with current date and message ID headers
msg.date -= 3600                        # change date to 1 hour ago
msg.subject = 'This is important'       # add subject
msg.headers.set('Priority', 'urgent')   # add custom header

msg.body = Text.new('hello, world!', 'plain', 'charset' => 'us-ascii')
#
# The previous line is equivalent to the following snippet:
#
#   msg.body = 'hello, world!'
#   msg.headers.set('Content-Type', 'text/plain; charset=us-ascii')

msg.from = {'boss@example.com' => 'Boss Man'}            # mailbox hash
msg.bcc  = 'boss+home@example.com'                       # mailbox string
msg.cc   = %w(secretary@example.com manager@example.com) # mailbox array
msg.to   = {
  'list@example.com' => nil,                             # no name display
  'john@example.com' => 'John Doe',
  'jane@example.com' => 'Jane Doe',
}

msg.to_s  # ready to be sent via SMTP