test gmail sender

parent b3ffebca
Pipeline #908 failed with stages
in 0 seconds
class UsersController < ApplicationController class UsersController < ApplicationController
def new
end
def register_begin def register_begin
@email = User.new(params[:email])
end
def create
@email = User.new(params[:email])
if @email.save
UserMailer.with(email: @email).welcome_email.deliver_later
redirect_to mail_register_path
else
redirect_to register_begin_path
end
end
def mail_register
end end
end end
class ConfirmMailer < ApplicationMailer
def new_confirm_email
@email = params[:email]
mail(to: 'phuocht@zigexn.vn', subject: "You have to confirm")
end
end
class UserMailerPreview < ActionMailer::Preview
def welcome_email
UserMailer.with(email: User.first).welcome_email
end
end
class UserMailer < ActionMailer::Base
default from: 'phuocht@gmail.com'
def welcome_email
@email = params[:email]
mail(to: @email, subject: 'Welcome to My Awesome Site')
end
end
<!DOCTYPE html>
<html> <html>
<head> <head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head> </head>
<body> <body>
<p>You got a new order from <%= @email %>!</p> <h1>Welcome to example.com, <%= @user.name %></h1>
<p> <p>
Order details<br> You have successfully signed up to example.com,
-------------------------- your username is: <%= @user.login %>.<br>
</p>
sdaasdsdaasd
<p>
Message:<br>
----------
</p> </p>
<p>Thanks for joining and have a great day!</p>
</body> </body>
</html> </html>
===============================================
You have successfully signed up to gmail.com,
Thanks for joining and have a great day!
<div class="container">
<div class="text-center label">
<strong>Register</strong>
</div>
<div class="row">
Thank you for register our service, an confirmation email with registration link<br>
has been sent to your email. Please check your email within 24 hours.<br>
Please note that the registration link is only valid for 24 hours.<br>
Over that period, you will have to register your email again.
</div>
</div>
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
<strong>Register</strong> <strong>Register</strong>
</div> </div>
<div class="row"> <div class="row">
<div class="col-1 email-text">Email</div> <%= form_for(@email) do |f| %>
<input type="text" class="form-control col-sm" placeholder="Email" aria-label="Email" > <strong>Email</strong>
</div> <%= f.text_field :email, class: 'col-6'%>
<div class="text-center confirm-email-btn"> <div class="text-center confirm-email-btn">
<button class="btn btn-outline-danger confirm"><strong class="text-confirm">Confirm your email</strong></button> <%= f.submit 'Confirm your email', class: 'btn btn-outline-danger confirm' %>
</div>
<% end %>
</div> </div>
</div> </div>
...@@ -2,6 +2,8 @@ require_relative 'boot' ...@@ -2,6 +2,8 @@ require_relative 'boot'
require 'open-uri' require 'open-uri'
require 'rails/all' require 'rails/all'
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
......
...@@ -27,11 +27,24 @@ Rails.application.configure do ...@@ -27,11 +27,24 @@ Rails.application.configure do
config.cache_store = :null_store config.cache_store = :null_store
end end
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
# Store uploaded files on the local file system (see config/storage.yml for options) # Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local config.active_storage.service = :local
# Don't care if the mailer can't send. # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
......
...@@ -29,5 +29,8 @@ ...@@ -29,5 +29,8 @@
# To learn more, please read the Rails Internationalization guide # To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html. # available at http://guides.rubyonrails.org/i18n.html.
GMAIL_USERNAME: 'phuocht@zigexn.vn'
GMAIL_PASSWORD: 'Thienphuoc0123'
en: en:
hello: "Hello world" hello: "Hello world"
Rails.application.routes.draw do Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
match '/register/1', to: 'users#register_begin', via: 'get' match '/register/1', to: 'users#register_begin', via: 'get', as: :register_begin
match '/register/2', to: 'users#mail_register', via: 'get', as: :mail_register
resources :users resources :users
resources :jobs resources :jobs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment