2018年12月28日|
|
コメントなし
メールサーバーからiPhoneメールにプッシュ通知を送る
目次
概要
[breadcrumb]メールサーバーからiPhoneメールにプッシュ通知を送る方法を試してみました。
プッシュ通知にはz-pushというライブラリを使用します。
インストール
z-push.orgのダウンロードサイトから最新版のz-pushをダウンロードします。
バージョン番号は適宜変えてください。
$ cd /var/www/ # 場所はてきとう。今回はここにインストールすることにします。 $ wget http://download.z-push.org/final/2.3/z-push-2.3.9.tar.gz $ tar -zxvf z-push-2.3.9.tar.gz $ ln -s z-push-2.3.9 z-push
/var/www/z-push/config.php設定
define('TIMEZONE', 'Asia/Tokyo');
define('STATE_DIR', '/var/www/z-push/');
define('BACKEND_PROVIDER', 'BackendIMAP');
/var/www/z-push/backend/imap/config.php設定
// IMAPサーバー指定
define('IMAP_SERVER', 'mail.yourdomain.com');
// IMAPのポート番号指定
define('IMAP_PORT', 993);
// IMAPオプション
// '/ssl/validate-cert' IMAPS TLS 証明書の場合
// '/notls/norsh' IMAP の場合
define('IMAP_OPTIONS', '/ssl/validate-cert');
define('IMAP_FOLDER_CONFIGURED', true);
// Sender address rejected: need fully-qualified address;エラーに対処する場合
define('IMAP_DEFAULTFROM', '@braveam.com');
// smtpメソッド
define('IMAP_SMTP_METHOD', 'smtp');
Apacheの場合(/etc/httpd/conf.d/z-push.conf)の設定
<VirtualHost *:443>
SSLEngine on
# 適宜、自分のSSLファイルを指定
SSLCertificateFile /etc/your_enccryptdir/cert.pem
SSLCertificateKeyFile /etc/your_encryptdir/privkey.pem
SSLCertificateChainFile /etc/your_encryptdir/chain.pem
SSLCipherSuite HIGH:MEDIUM:!aNULL:!SSLv2:+SHA1:+MD5:+HIGH:+MEDIUM
DocumentRoot "/var/www/z-push/"
ServerName mail.yourdomain.com
ErrorLog logs/mail.yourdomain.com_error_log
CustomLog logs/mail.yourdomain.com_access_log combined
<Directory /var/www/z-push>
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag magic_quotes_runtime off
php_flag short_open_tag on
</Directory>
Alias /Microsoft-Server-ActiveSync /var/www/z-push/index.php
SetEnvIf Request_URI "^/Microsoft-Server-ActiveSync(/|$)" zpush_request
</VirtualHost>
Nginxの場合(/etc/nginx/conf.d/z-push.conf)設定
server {
listen 443;
server_name mail.braveam.com;
access_log /var/log/nginx/mail.yourdomain.com_ssl_access.log main;
error_log /var/log/nginx/mail.yourdomain.com_ssl_error.log;
root /var/www/z-push/current/public;
ssl_certificate /etc/your_encryptdir/fullchain.pem;
ssl_certificate_key /etc/your_encryptdir/privkey.pem;
location /Microsoft-Server-ActiveSync {
root /var/www/z-push/;
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTPS on;
}
}
再起動
# Apacheの場合 $ systemctl restart httpd # nginxの場合 $ systemctl restart php-fpm $ systemctl restart nginx
動作確認
https://mail.yourdomain.com/Microsoft-Server-ActiveSync にアクセスして以下が表示されればOK
GET not supported This is the Z-Push location and can only be accessed by Microsoft ActiveSync-capable devices
iPhoneの設定
設定 > アカウントとパスワード > アカウントを追加 > Exchange を選択
適宜、以下の情報を設定。
| メール | user_name@yourdomain.com |
| サーバー | mail.yourdomain.com |
| ドメイン | yourdomain.com |
| ユーザ名 | user_name |
| パスワード | (IMAPのパスワード) |