Class: Mail::XOauthSMTP

Inherits:
SMTP
  • Object
show all
Defined in:
lib/mail/network/delivery_methods/xoauth_smtp.rb

Defined Under Namespace

Classes: MissingAuthInfo

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ XOauthSMTP

Returns a new instance of XOauthSMTP.



5
6
7
8
9
# File 'lib/mail/network/delivery_methods/xoauth_smtp.rb', line 5

def initialize(values)
  fail MissingAuthInfo unless values[:address]
  fail MissingAuthInfo unless values[:access_token]
  super values
end

Instance Method Details

#deliver!(mail) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mail/network/delivery_methods/xoauth_smtp.rb', line 11

def deliver!(mail)
  smtp_from, smtp_to, message = check_delivery_params(mail)

  smtp = Net::SMTP.new('smtp.gmail.com', 587)
  smtp.enable_starttls_auto
  smtp.start('gmail.com', settings.fetch(:address), settings.fetch(:access_token), :xoauth2) do |connection|
    response = connection.sendmail(message, smtp_from, smtp_to)
  end

  if settings[:return_response]
    response
  else
    self
  end
end