How to send email via Gmail in ruby

Here is the example:

1
2
3
4
5
6
7
8
9
10
11
12
13
require 'gmail'
user = "GMAIL EMAIL ADDRESS"
pass = "GMAIL PASSWORD"
gmail = Gmail.connect(user, pass)
email = gmail.compose do
subject "EMAIL SUBJECT"
body "EMAIL BODY TEXT"
add_file "/var/tmp/TEST.jpg"
end
email.deliver!

Make sure turn on ‘access from less secure app’ in your Google account settings:

send email via Gmail in ruby

Share