can not connect the apples APN server for pusNotification from by PHP code - iphone

To connect my server with the APN server I use the following code.
// coonecting the apn server
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $errorNo, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
But I am failed to connect, I print the $errorNo and $errorString
the output was:
error: Connection timed out
errorNo: 110
But I am also getting the following warnings in errorLog:
Unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/riseupla/public_html/applications/apn/apn.php on line 35
What shoud I do?
NOTE:
I can send push notifications by my mac project (using push me baby project).
But my PHP project failed to connect.

You do not say if you run the php from a different machine than your Mac, but if you are using a hosted service for your php site, then it might be that the ISP has blocked port 2195 (and 2196).
Try to run your php on the same machine as you use when running your Mac project and see if this helps. If that's the case, then you ISP has most likely blocked the ports, and you will have to either find a different ISP or have them open the ports.
Claus

You probably solved it.
But for those interested to find out if the ports are blocked: IF you have SSH access to the server a simple way is to check if you can telnet to the server. This way i found out my provider blocked the ports...
:~ telnet gateway.sandbox.push.apple.com 2195
:~ telnet gateway.sandbox.push.apple.com 2196
You should see something like:
Trying 17.172.232.236...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

may be that your server's IP variety, it must be fixed so work!!

Related

Sendmail Error : opendaemonsocket: daemon TLSMTA: cannot bind: Address already in use

I am installing sendmail/dovecot on my mail sever.
I edited file /etc/mail/sendmail.mc
and add the below lines to make sure the domain name is used in sending mail
#add for domain email by deo malamo
define(`confDOMAIN_NAME', `desaonline.co.tz')dnl
FEATURE(`relay_entire_domain')dnl
#end add domail based email by deo malamo
i installed and Used tls/ssl from Let's Encrypt
#add for Let's Encrypt ssl by deo malamo
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`CERT_DIR', `/etc/letsencrypt/live/mail.desaonline.co.tz/')dnl
define(`confCACERT', `CERT_DIR/chain.pem')dnl
define(`confCACERT_PATH',`/etc/ssl/certs/')dnl
define(`confCLIENT_CERT', `CERT_DIR/cert.pem')dnl
define(`confCLIENT_KEY', `CERT_DIR/privkey.pem')dnl
define(`confSERVER_CERT', `CERT_DIR/cert.pem')dnl
define(`confSERVER_KEY', `CERT_DIR/privkey.pem')dnl
FEATURE(`no_default_msa')dnl
DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
#DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl
#DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
#end add Let's Encrypt ssl by dmalamo
MY PROBLEM is the ports 25,465 and 587 are coming up and then shutdown because of port already in use ,Can any one assist me to fix this problem?
When i save the config (/etc/mail/sendmail.mc) and restart sendmail ,port 465 seems to be used and shutdown the whole outgoing ports 25,465 and 587.
logs file have the below entries
daemon TLSMTA: problem creating SMTP socket
Feb 9 13:26:43 mail sm-mta[20646]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon TLSMTA: cannot bind: Address already in use
NOQUEUE: SYSERR(root): opendaemonsocket: daemon TLSMTA: cannot bind: Address already in use
daemon TLSMTA: problem creating SMTP socket
NOQUEUE: SYSERR(root): opendaemonsocket: daemon TLSMTA: server SMTP socket wedged: exiting
MY PROBLEM is the ports 25,465 and 587 are coming up and then shutdown because of port already in use ,Can any one assist me to fix this problem?
Short list to check...
1st) have You compiled sendmail.mc into sendmail.cf ?
2nd) TLSMTA: cannot bind: Address already in use... means that one process already use this port (smtps: 465),
- check who is using port (e.g. "netstat -lntp|grep 465")
- and stop this, sometimes port can be in use by connection, maybe instead restart You should: stop, wait few sec./minutes and then start sendmail
- "netstat -lntp|grep sendmail" can be usefull to see sendmail's listening ports
- before start be sure that ports are not occupied (not in use)
- problem may also be in SELINUX (investigate how to allow program to use ports)
Regards
K.

How configure roundcube to work with imaps?

I recently installed Postfix, Dovecot to setup a mail server on my own VPS ( using this tutorial: Email with Postfix, Dovecot, Mysql)
Imaps server uses port 993 for Authentication, and Postfix uses port 25 to send mails.
In this tutorial, users stored in a Database ( so imaps use mysql to authenticate users).
i'm sure every thing works fine with imaps and postfix , because few days ago i installed Kmail client (on my linux) and receive mails from my server. sending mails also works fine, i sent a mail to Gmail and google received it without a problem (in my "Gmail inbox" not spam folder)
So to get to my Emails from a web mail client, i installed Roundcube on /var/www/mail directory.
I configured Roundcube many times. but each time it gives me this Error:
IMAP Error: Login failed for [me#mydomain] from X.x.X.x . Empty
startup greeting (localhost:993) in
/var/www/mm/program/lib/Roundcube/rcube_imap.php on line 184 (POST
/mm/?_task=login?_task=login&_action=login)
When i do log in from roundcube, imap server says ( in /var/log/mail.log ):
May 20 07:05:16 my-server dovecot: imap-login: Disconnected (no auth
attempts): rip=::1, lip=::1, TLS handshaking: Disconnected
Here is my roundcube config file :
$config['db_dsnw'] = 'mysql://roundcubeuser:myPassword#localhost/roundcubemail';
// ----------------------------------
// IMAP
// ----------------------------------
$config['debug_level'] = 13;
$config['default_host'] = 'ssl://127.0.0.1';
$config['default_port'] = 993;
// ----------------------------------
// SMTP
// ----------------------------------
$config['smtp_server'] = 'ssl://localhost';
What's the problem? i really have no idea what is happening !
Thank you.
I'm using postfix + dovecot + roundcube a few months now and it's working for me. In my configuration, postfix rejects plaintext sessions, so roundcube has to connect with ssl - and it's working.
This is from my main.inc.php. I don't remember editing anything here, it's just the initial config created during the installation.
Now that I'm looking at it, default_port doesn't make any sense, I think it's just ignored.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// Supported replacement variables:
// %n - http hostname ($_SERVER['SERVER_NAME'])
// %d - domain (http hostname without the first part)
// %s - domain name after the '#' from e-mail address provided at login screen
// For example %n = mail.domain.tld, %d = domain.tld
// TCP port used for IMAP connections
$rcmail_config['default_port'] = 143;
$rcmail_config['default_host'] = array("ssl://localhost:993");
// TCP port used for IMAP connections
$rcmail_config['default_port'] = 143;
In case the other answer does not work, this is what worked for me. My config.inc.php now contains:
$config['default_host'] = 'ssl://localhost';
$config['default_port'] = 993;
NOTE: using tls://localhost did not work for me. I had to specify ssl:// as the URI scheme.
Via PhpMyAdmin, I also ran this SQL command (all my user accounts are on the same machine that runs RoundCube):
UPDATE `rc_users` SET `mail_host`='ssl://localhost'
I got the port number 993 from running sudo netstat -tulnp in order to determine the port on which Dovecot was listening.

Bugzilla - Email not working

I have installed Bugzilla-4.4 in my new Ubuntu Machine. When I submit a new bug, I got the email sent notification. But the sent email is not received by the recipients . I am using Sendmail mail configuration in Bugzilla. I have also tested "Test" mail configuration in which the mail is logged in bugzilla-4.4/data/mailer.testfile successfully. When I check my mail.log file I found the following:
(1001/1001), delay=3+15:58:59, xdelay=00:00:00, mailer=esmtp, pri=47643784, relay=mailrelay.netcon.in., dsn=4.0.0, stat=Deferred: Connection timed out with mailrelay.netcon.in.
I have no idea what to do.Is anything I missed out while Sendmail configuration? Any help!!
Try nc from command line:
nc mailrelay.netcon.in 25
which should result in something like:
220 mailrelay.netcon.in ESMTP Postfix
If not check for internet connection and/or router firewall rules.

Apns php error "Failed to connect to APNS: 110 Connection timed out."

I have done apns code for php and objective c from this Apns code
and setup certificate from this link
Sandbox and production apns for sending notification to ios devices is working perfectly on my server.I moved code and same certificate to client server then sending notification is not working.
I debug all php code and found that it stops at this line of code
private function _connectSSLSocket($development) {
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $this->apnsData[$development]['certificate']);
$this->sslStreams[$development] = stream_socket_client($this->apnsData[$development]['ssl'], $error, $errorString, 100, (STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT), $ctx);
if(!$this->sslStreams[$development]){
$this->_triggerError("Failed to connect to APNS: {$error} {$errorString}.");
unset($this->sslStreams[$development]);
return false;
}
return $this->sslStreams[$development];
}
apns.log file shows the error "Failed to connect to APNS: 110 Connection timed out."
Not getting the mistake. Why this error am i getting and not sending notification to ios devices ? Can anyone guide me for this ?
Finally i took vps instead of shared hosting.
Lucabro's comments helped me to solve. Thanks Lucabro.
A good solution is to use a cloud function like firebase to run the actual apns connection and expose an API for your other backend in the shared hosting.
This is what I used when I run in this problem.
Firebase cloud functions are convenient easy to develop and virtually free.
https://firebase.google.com/docs/functions
I'll post my solution to sometimes next week.

SMTP Error <<: 503 AUTH command used when not advertised

I am facing this error in Webmail Lite.
I have Exim installed. Here is a snippet of the auth block:
PLAIN:
driver = plaintext
server_set_id = $auth2
server_prompts = :
.ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
.endif
server_condition = “${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{/etc/$domain/passwd}{$value}{*:*}}}}}{1}{0}}”
I have the passwd stored in the following format:
username:{MD5}asddfasdlasdkandlanskfdaf
How do I get AUTH enabled and working ?
Thanks in advance.
One reason for this error message is sending HELO instead of EHLO, or sending EHLO in the wrong order.
But this message can occur even if EHLO is used, when the server is running Exim.
On my server, I found the solution. In WHM > Home > Service Configuration > Exim
Configuration Manager, the option "Require clients to connect with SSL
or issue the STARTTLS command before they are allowed to authenticate
with the server" was set to the default (On). I'm not sure if I did this
or not, and it is ordinarily a great idea for security, but forces the
mailserver to enable (advertise) only the STARTTLS command, not AUTH. So
when my script sends AUTH, the error message the server sends is correct.
Further information is at http://blog.networkpresence.co/?p=8923 .
Someday when I have time I will find out how to change my script to use
TLS, so I can turn that Exim option On for security.
In my case,this error not coming regularly.some time it works but some time it gives this error.(SMTP Error: Could not authenticate.)
I debug this then I found this
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "503 AUTH command used when not advertised "
SMTP -> get_lines(): $data is "503 AUTH command used when not advertised "
SMTP -> FROM SERVER:503 AUTH command used when not advertised
SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised
SMTP Error: Could not authenticate.