create sender mailer

parent 4d40a363
Pipeline #951 canceled with stages
in 0 seconds
...@@ -21,3 +21,4 @@ ...@@ -21,3 +21,4 @@
.text-confirm { .text-confirm {
font-size: 26px; font-size: 26px;
} }
class UsersController < ApplicationController class UsersController < ApplicationController
def new def new
@email = User.new
end
def register_begin
@email = User.new(params[:email])
end end
def create def create
@email = User.new(params[:email]) @email = User.new(email: params[:user][:email])
if @email.save if @email.save
UserMailer.with(email: @email).welcome_email.deliver_later binding.pry
UserMailer.register_email(params[:user][:email]).deliver_later
redirect_to mail_register_path redirect_to mail_register_path
else else
redirect_to register_begin_path redirect_to register_begin_path
......
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com' default from: 'phuocht@zigexn.vn'
layout 'mailer' layout 'mailer'
end end
class UserMailerPreview < ActionMailer::Preview
def welcome_email
UserMailer.with(email: User.first).welcome_email
end
end
class UserMailer < ActionMailer::Base class UserMailer < ActionMailer::Base
default from: 'phuocht@gmail.com' def register_email(email)
def welcome_email @email = email
@email = params[:email]
mail(to: @email, subject: 'Welcome to My Awesome Site') mail(to: @email, subject: 'Welcome to My Awesome Site')
end end
end end
===============================================
You have successfully signed up to gmail.com,
Thanks for joining and have a great day!
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
<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>
<h1>Welcome to example.com, <%= @user.name %></h1> <h1>Welcome to example.com, <%= @email %></h1>
<p> <p>
You have successfully signed up to example.com, You have successfully signed up to example.com,
your username is: sadsad.<br> your username is: <%= @email %>.<br>
</p>
<p>
To login to the site, just follow this link:....
</p> </p>
<p>Thanks for joining and have a great day!</p> <p>Thanks for joining and have a great day!</p>
</body> </body>
......
=================================================
Welcome to example.com, <%= @email %>
HELLO
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
<div class="text-center label"> <div class="text-center label">
<strong>Register</strong> <strong>Register</strong>
</div> </div>
<div class="row"> <div class="form-register">
<%= form_for(@email) do |f| %> <%= form_for(@email) do |f| %>
<strong>Email</strong> <div class="text-center email-input">
<%= f.text_field :email, class: 'col-6'%> <strong>Email</strong>
<%= f.text_field :email %>
</div>
<div class="text-center confirm-email-btn"> <div class="text-center confirm-email-btn">
<%= f.submit 'Confirm your email', class: 'btn btn-outline-danger confirm' %> <%= f.submit 'Confirm your email', class: 'btn btn-outline-danger confirm font-weight-bold' %>
</div> </div>
<% end %> <% end %>
</div> </div>
......
...@@ -10,7 +10,6 @@ module Venjob ...@@ -10,7 +10,6 @@ module Venjob
class Application < Rails::Application class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version. # Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2 config.load_defaults 5.2
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers # Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading # -- all .rb files in that directory are automatically loaded after loading
......
...@@ -27,24 +27,25 @@ Rails.application.configure do ...@@ -27,24 +27,25 @@ 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.active_job.queue_adapter = :async
config.action_mailer.default_url_options = { host: "localhost:3000" }
# config.action_mailer.default_options = { from: 'support@venjob.com' }
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.zigexn.vn",
port: 587,
domain: "zigexn.vn",
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: "plain",
enable_starttls_auto: true
}
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
......
# Rename this file to local_env.yml
# Add account settings and API keys here.
# This file should be listed in .gitignore to keep your settings secret!
# Each entry gets set as a local environment variable.
# This file overrides ENV variables in the Unix shell.
# For example, setting:
# GMAIL_USERNAME: 'Your_Gmail_Username'
# makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
GMAIL_USERNAME: 'phuocht@zigexn.vn'
GMAIL_PASSWORD: 'Thienphuoc123'
# PASSWORD_TPM: 'vjkjlbgoxqxvnbac'
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
# #
# 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,13 +2,14 @@ Rails.application.routes.draw do ...@@ -2,13 +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 get '/register/1', to: 'users#new', as: :register_begin
match '/register/2', to: 'users#mail_register', via: 'get', as: :mail_register get '/register/2', to: 'users#mail_register', 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 :user_mailer
resources :users resources :users
resources :top_pages resources :top_pages
resources :industries resources :industries
......
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