-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.rb
More file actions
30 lines (25 loc) · 677 Bytes
/
Copy pathemail.rb
File metadata and controls
30 lines (25 loc) · 677 Bytes
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
26
27
28
29
30
require 'rubygems'
require 'postmark'
def usage
puts 'Email a message using PostMark.'
puts
puts %|Usage: email.rb --postmark-key=... --to=you@example.com --from=me@example.com --subject='...' --body='...'|
exit 1
end
def load_arg(name)
found = ARGV.grep /^--#{name}=.+/
return nil if found.empty?
found.first.split('=').last
end
POSTMARK_API_KEY = load_arg('postmark-key') || usage
to = load_arg('to') || usage
from = load_arg('from') || usage
subject = load_arg('subject') || usage
body = load_arg('body') || usage
mail = Postmark::ApiClient.new(POSTMARK_API_KEY, secure: true)
mail.deliver(
from: from,
to: to,
subject: subject,
text_body: body
)