mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Email server configuration (#246)
Co-authored-by: riggraz <riccardo.graziosi97@gmail.com>
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "notifications@astuto.io"
|
||||
layout 'mailer'
|
||||
helper :application
|
||||
|
||||
after_action :set_mail_from_for_multitenancy
|
||||
|
||||
private
|
||||
|
||||
def set_mail_from_for_multitenancy
|
||||
if Rails.application.multi_tenancy?
|
||||
from = "#{Current.tenant_or_raise!.site_name} <#{ENV.fetch('EMAIL_MAIL_FROM', 'notifications@astuto.io')}>"
|
||||
mail.from = from
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,26 @@ Rails.application.configure do
|
||||
config.cache_store = :null_store
|
||||
end
|
||||
|
||||
if ENV['EMAIL_DELIVERY_METHOD'] == "smtp"
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = {
|
||||
address: ENV['EMAIL_SMTP_HOST'],
|
||||
port: ENV.fetch("EMAIL_SMTP_PORT") { 25 },
|
||||
domain: ENV["EMAIL_SMTP_HELO_DOMAIN"],
|
||||
user_name: ENV.fetch("EMAIL_SMTP_USER"),
|
||||
password: ENV.fetch("EMAIL_SMTP_PASS"),
|
||||
authentication: ENV.fetch("EMAIL_SMTP_AUTH", "plain"),
|
||||
enable_starttls_auto: ActiveModel::Type::Boolean.new.cast(ENV.fetch("EMAIL_SMTP_STARTTLS_AUTO", "true")),
|
||||
openssl_verify_mode: ENV["EMAIL_SMTP_OPENSSL_VERIFY_MODE"],
|
||||
tls: ENV["EMAIL_SMTP_TLS"]
|
||||
}
|
||||
end
|
||||
|
||||
config.action_mailer.default_options = {
|
||||
from: ENV.fetch("EMAIL_MAIL_FROM", "Astuto <notifications@astuto.io>"),
|
||||
reply_to: ENV.fetch("EMAIL_MAIL_REPLY_TO", ENV.fetch("EMAIL_MAIL_FROM", "Astuto <notifications@astuto.io>"))
|
||||
}
|
||||
|
||||
# Store uploaded files on the local file system (see config/storage.yml for options).
|
||||
config.active_storage.service = :local
|
||||
|
||||
|
||||
@@ -66,6 +66,28 @@ Rails.application.configure do
|
||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||
config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
if ENV['EMAIL_DELIVERY_METHOD'] == "smtp"
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = {
|
||||
address: ENV['EMAIL_SMTP_HOST'],
|
||||
port: ENV.fetch("EMAIL_SMTP_PORT") { 25 },
|
||||
domain: ENV["EMAIL_SMTP_HELO_DOMAIN"],
|
||||
user_name: ENV.fetch("EMAIL_SMTP_USER"),
|
||||
password: ENV.fetch("EMAIL_SMTP_PASS"),
|
||||
authentication: ENV.fetch("EMAIL_SMTP_AUTH", "plain"),
|
||||
enable_starttls_auto: ActiveModel::Type::Boolean.new.cast(ENV.fetch("EMAIL_SMTP_STARTTLS_AUTO", "true")),
|
||||
openssl_verify_mode: ENV["EMAIL_SMTP_OPENSSL_VERIFY_MODE"],
|
||||
tls: ENV["EMAIL_SMTP_TLS"]
|
||||
}
|
||||
end
|
||||
|
||||
if ENV['EMAIL_CONFIRMATION']
|
||||
config.action_mailer.default_options = {
|
||||
from: ENV.fetch("EMAIL_MAIL_FROM", "Astuto <notifications@astuto.io>"),
|
||||
reply_to: ENV.fetch("EMAIL_MAIL_REPLY_TO", ENV.fetch("EMAIL_MAIL_FROM", "Astuto <notifications@astuto.io>"))
|
||||
}
|
||||
end
|
||||
|
||||
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
||||
# the I18n.default_locale when a translation cannot be found).
|
||||
config.i18n.fallbacks = true
|
||||
|
||||
@@ -40,6 +40,11 @@ Rails.application.configure do
|
||||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
config.action_mailer.default_options = {
|
||||
from: "notifications@astuto.io",
|
||||
reply_to: "notifications@astuto.io"
|
||||
}
|
||||
|
||||
# Tell Action Mailer not to deliver emails to the real world.
|
||||
# The :test delivery method accumulates sent emails in the
|
||||
# ActionMailer::Base.deliveries array.
|
||||
|
||||
@@ -18,7 +18,7 @@ Devise.setup do |config|
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
# note that it will be overwritten if you use your own mailer class
|
||||
# with default "from" parameter.
|
||||
config.mailer_sender = 'notifications@astuto.io'
|
||||
config.mailer_sender = ''
|
||||
|
||||
# Configure the class responsible to send e-mails.
|
||||
# config.mailer = 'Devise::Mailer'
|
||||
|
||||
Reference in New Issue
Block a user