/
send_g_tester.rb
66 lines (56 loc) · 1.45 KB
/
send_g_tester.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'sendgrid-ruby'
require 'mail'
require 'io/console'
# write a test e-mail with SendGrid
puts ""
puts "-----------------------------"
puts "Send an e-mail using SendGrid"
puts "-----------------------------"
puts ""
puts ""
puts "Enter your SENDGRID user name (Please be accurate)"
puts "--------------------------------------------------"
puts ""
SENDGRID_USERNAME = gets.chomp
puts ""
puts "Enter your password (Please be accurate)"
puts "----------------------------------------"
puts ""
print "Password will be hidden:"
puts ""
SENDGRID_PASSWORD = STDIN.noecho(&:gets).chomp
puts ""
puts "Enter recipient's e-mail address"
puts "--------------------------------"
puts ""
recipient = gets.chomp
puts ""
puts "Enter your e-mail address"
puts "--------------------------"
puts ""
email = gets.chomp
puts ""
puts "Enter email subject line"
puts "-------------------------"
puts ""
subject = gets.chomp
puts ""
puts "Enter body text"
puts "---------------"
puts ""
body = gets.chomp
puts ""
puts ""
puts "Thank you. Your email may take 3-5 minutes to process. Please be patient."
puts ""
puts ""
# As a hash
client = SendGrid::Client.new(api_user: "#{SENDGRID_USERNAME}", api_key: "#{SENDGRID_PASSWORD}")
mail = SendGrid::Mail.new do |m|
m.to = "#{recipient}"
m.from = "#{email}"
m.subject = "#{subject}"
m.text = "#{body}"
end
puts client.send(mail)
# {"message":"success"}