Coder Social home page Coder Social logo

ikamail's Introduction

一括メールシステム ikamail

ikamail は組織内に一括でメールを送信するためのシステムです。(作成中)

ユーザーのメールアドレス情報をLDAPから取得し、条件に一致するユーザーに対してメールを一括で送信します。

環境

  • 言語

    • Ruby 2.5 以上 (2.6 以上推奨)
    • Node.js 10以上 (アセットファイルコンパイル時のみ使用、12以上推奨)
  • OS

    • Ubuntu 18.04LTS、20.04LTS(予定)
    • CentOS 7(with SCL)、8
  • データベース

    • MariaDB 10.1 以上、10.2.2 以上推奨
  • ブラウザ

    • Microsoft Edge
    • Mozilla Firefox
    • Apple Safari
    • Google Chrome ※ Internet Explorerには対応していません。

OS設定

本番環境でのDelayedJobが大量のファイルを監視を行う関係で、inotifyの監視数上限(デフォルトは8192)を超えてしまう場合があります。DelayedJobのデーモンでエラーが出る場合は、"/etc/sysctl.conf"に下記を追加して、sysctl -pで読み込みを行ってください。

fs.inotify.max_user_watches = 32768

設定可能な上記の最大値は524288です。監視数の数だけメモリを消費しますので、メモリが少ない環境では注意して設定してください。

データベース設定

拡張面の漢字や絵文字等に対応するためにはutf8mb4でなければなりません。しかし、utf8mb4では255文字が767バイトを越えてしまうため、innodb_large_prefixが有効でなければなりません。MariaDB 10.2.1 以下でutf8mb4を使用する場合は以下のようにmy.cnfに追加してください。これはアプリ用のデータベースを作成する前に実施する必要があります。

[client]
default-character-set = utf8mb4

[server]
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table
innodb_large_prefix
innodb_default_row_format = DYNAMIC

MariaDB 10.2.2 以上は上記のInnoDB設定がデフォルトであるため、後半は不要です。

デプロイ

下記コマンドでクローンおよび必要なライブラリをインストールします。

git clone https://github.com/kue-ipc/ikamail.git
cd ikamail
bundle install --deployment --without development test
bundle exec rails yarn:install

コマンドがエラーになった場合は、Ruby、Node.js、Yarnが正常にインストールされているかを確認してください。

下記コマンドでcredentialsを作成します。

EDITOR=vim bundle exec rails credentials:edit

redentialsにデータベースやLDAPのアカウント情報をYAML形式で記入してください。最初の実行で"config/master.key"と"config/credentials.yml.enc"を新たに作成されます。編集する場合は、上記のコマンドを再度実行してください。追加する項目は"config/credentials.yml.sample"を参考にしてください。"config/master.key"は漏洩しないように注意してください。ファイルではなく、環境変数RAILS_MASTER_KEYで渡すようにすることもできます。

続いてLDAPの設定を行います。下記コマンドで"config/ldap_production.yml.sapmle"のコピーとして"config/ldap_production.yml"を作成し、編集します。

cp -ip config/ldap_production.yml.sapmle config/ldap_production.yml
vim config/ldap_production.yml

サンプルを参考に、バインドアカウント以外のLDAP情報を記入してください。バインドアカウント情報はcredentialsに記入してください。

下記コマンドでアセットファイルを事前コンパイルを行います。

RAILS_ENV=production bundle exec rails assets:precompile

データベースに専用のデータベースとユーザーを作成します。データベースのデフォルト接続先はlocalhostのMariaDBで、データベース名はikamailです。環境変数DATABASE_URLを使用してください。

create database ikamail;
create user ikamail@'localhost' identified by 'DBユーザーのパスワード';
grant all privileges on ikamail.* to ikamail@'localhost';
flush privileges;

データベースの順ができたら、データベースをマイグレーションしてください。

RAILS_ENV=production bundle exec rails db:migrate

あとは、scriptsにあるサンプルを参考にサービスに登録して、起動してください。production環境ではDelayedJobを有効にすることも忘れないでください。

定期的な処理はwheneverでクーロン登録ができます。

bundle exec whenever --update-crontab

登録情報の変更等はconfig/schedule.rbを書き換えてください。その他、batch/cronにもバッチ処理のシェルのサンプルがあります。

開発とテスト

テスト用LDAPサーバーは"test/ldap"にあります。slapdとldap-utilsを入れておいてください。./test/ldap/run-serverでサーバーが起動します。初期データはbase.ldifを投げてください。Ubuntuでslapdサービスを起動している場合は、exmaple.ldifを投げてください。状況に応じて、config/ldap.ymlを書き換えてください。

テストにはヘッドレスなChromiumとWebDriverが必要ですが、現在テストは実装されていません。

制限事項

  • 宛先の最大数よりPostfixのsmtpd_recipient_limitが大きくなければならない。
  • sendmailではコマンドの引数制限による制限がある。
  • メール送信がエラーになってもエラーにならない。(メール送信エラーが検知できない)
  • 日本語のみ対応しています。言語切替はできません。

ikamail's People

Contributors

dependabot[bot] avatar raccy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.