Skip to content

Instantly share code, notes, and snippets.

@hoksilato
Created December 8, 2015 16:11
Show Gist options
  • Save hoksilato/93a5253847af595e297c to your computer and use it in GitHub Desktop.
Save hoksilato/93a5253847af595e297c to your computer and use it in GitHub Desktop.
Sending email with Gmail SMTP
require 'net/smtp'
class OrdersController < ApplicationController
def finish
@order = Order.find(params[:id])
order_finish_url = url_for :controller => 'orders', :action => 'finish', :id => @order.id, :email => false
if params[:email].nil? || params[:email].empty?
message = <<EOF
From: Coder Restaurant <[email protected]>
To: #{@order.customer_name} <#{@order.email}>
Subject: Coder Restaurant - Order succeeded!
Thank you for your order.
You can view your order detail at: #{order_finish_url}
EOF
#Using Block
smtp = Net::SMTP.new('smtp.gmail.com', 587 )
smtp.enable_starttls
smtp.start('gmail.com', '[email protected]', 'your-password', :login) do |smtp|
smtp.send_message message, '[email protected]', @order.email
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment