create interface mailer

parent 566e2225
Pipeline #911 failed with stages
in 0 seconds
// Place all the styles related to the Top_pages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.label {
font-size: 32px;
padding: 20px;
margin: 30px;
}
.email-text {
font-size: 24px;
}
.confirm-email-btn {
padding: 20px;
margin: 30px;
}
.confirm {
height: 150px;
width: 300px;
}
.text-confirm {
font-size: 26px;
}
class UsersController < ApplicationController
def new
end
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
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
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, <%= @user.name %></h1>
<p>
You have successfully signed up to example.com,
your username is: sadsad.<br>
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</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>
<div class="container">
<div class="text-center label">
<strong>Register</strong>
</div>
<div class="row">
<%= form_for(@email) do |f| %>
<strong>Email</strong>
<%= f.text_field :email, class: 'col-6'%>
<div class="text-center confirm-email-btn">
<%= f.submit 'Confirm your email', class: 'btn btn-outline-danger confirm' %>
</div>
<% end %>
</div>
</div>
...@@ -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
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,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"
...@@ -2,12 +2,14 @@ Rails.application.routes.draw do ...@@ -2,12 +2,14 @@ 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
resources :jobs resources :jobs
get 'detail/:id', action: :show, controller: 'jobs' , as: :job_detail get 'detail/:id', action: :show, controller: 'jobs' , as: :job_detail
match '/register/1', to: 'users#register_begin', via: 'get', as: :register_begin
match '/register/2', to: 'users#mail_register', via: 'get', as: :mail_register
get 'jobs/city/:converted_name', to: 'jobs#city_jobs', as: :city_jobs get 'jobs/city/:converted_name', to: 'jobs#city_jobs', as: :city_jobs
get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs
get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs
resources :users
resources :top_pages resources :top_pages
resources :industries resources :industries
resources :cities resources :cities
......
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