Tran Nghi's Site  - Make notes and share experience

PyAPNS – a Python library for interacting with the Apple Push Notification service

Author: Simon Whitaker at http://www.netcetera.org/

Seems that this project was no longer available when I am writing this post. Don’t know why.. but I just know that my webdev team is stilling using this great tool to make Push Notification on Apple devices.

Hereby the guidance for running it up.

Copy the pushmail.tar.gz to this location: /etc/postfix/pushmail.. and unzip it.

[email protected]:~#    chown nobody:mail /etc/postfix/pushmail
[email protected]:~#    chmod +x /etc/postfix/pushmail
[email protected]:~#    chmod +x /etc/postfix/pushmail/lib

add python script path to /etc/aliases

[email protected]:~#    vi /etc/aliases
## See man 5 aliases for format,
vmail: “|python /etc/postfix/pushmail/pushAPNs.py 2 >> /etc/postfix/pushmail/pushmail.log”

Run updating newaliases…

[email protected]:~#    newaliases

update table cho push noti

to get email notification, add alias [email protected] to mail alias column in virtual_aliases table of your database.
New email will pipe to pushmail.sh

My postfix’s configuration

[email protected]:~# vi /etc/postfix/main.cf
## Virtual domains, users, and aliases
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
#
#
[email protected]:~# cat /etc/postfix/mysql-virtual-mailbox-domains.cf
user = db_username
password = db_password
hosts = 127.0.0.1 localhost
dbname = db_name
query = SELECT 1 FROM virtual_domains WHERE name=’%s’
#
#
[email protected]:~# cat /etc/postfix/mysql-virtual-mailbox-maps.cf
user = db_username
password = db_password
hosts = 127.0.0.1 localhost
dbname = db_name
query = SELECT 1 FROM users WHERE email=’%s’
#
#
[email protected]:~# cat /etc/postfix/mysql-virtual-alias-maps.cf
user = db_username
password = db_password
hosts = 127.0.0.1 localhost
dbname = db_name
query = SELECT destination FROM virtual_aliases WHERE source=’%s’
#
#

Inside my PyAPNs.py

Fix with this:

Remember check and update your /etc/postfix/pushmail/production19.pem

[email protected]:~# cat /etc/postfix/pushmail/pushAPNs.py
apns = APNs(use_sandbox=False, cert_file=’/etc/postfix/pushmail/production19.pem’, key_file=’/etc/postfix/pushmail/production19.pem’)
apns_enhanced = APNs(use_sandbox=False, cert_file=’/etc/postfix/pushmail/production19.pem’, enhanced=True)
payload = Payload(alert= json_mess , sound=”default”)

 

Fix bug uft-8

update file pushAPNs.py

 

 

 

Message