Created
December 8, 2015 16:11
-
-
Save hoksilato/93a5253847af595e297c to your computer and use it in GitHub Desktop.
Sending email with Gmail SMTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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