CodeIgniter Forums
Sending multiple emails from my smtp-relay avoiding DoS - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Sending multiple emails from my smtp-relay avoiding DoS (/showthread.php?tid=84852)



Sending multiple emails from my smtp-relay avoiding DoS - rodrigoguariento - 11-16-2022

We are sending emails each 4 hours 3 times per working day. 

After a certain quantity of sent emails (near 2000 every day, never an exact number), we are getting the following return starting with:
Code:
220 smtp-relay.gmail.com ESMTP u13-XXXXXXXXXXXXXX023asm946523vkl.5 - gsmtp
<br /><pre>hello: 421 4.7.0 Try again later, closing connection. (EHLO) .............


Studying the case, I've reached at https://support.google.com/a/answer/2956491#zippy=%2Creview-sending-limits-for-the-smtp-relay-service :
[Image: DoS.png]


Taking a look in the email library in CI3 user guide in Email Preferences ( https://codeigniter.com/userguide3/libraries/email.html#email-preferences ), I've found smtp_keepalive.
[Image: ci3-preference.png]

Does someone know if the goal of smtp_keepalive would solve the "connection caching" mentioned in Google documentation above? Otherwise, what would be the solution to configure this "connection caching" when sending emails using the email library in CI3?

Thank you!


RE: Sending multiple emails from my smtp-relay avoiding DoS - rodrigoguariento - 01-04-2023

I've found the solution. There is an error in system/libraries/Email.php in all CodeIgniter 3 versions.

The original snippet code is:
PHP Code:
    /**
    * Get Hostname
    *
    * There are only two legal types of hostname - either a fully
    * qualified domain name (eg: "mail.example.com") or an IP literal
    * (eg: "[1.2.3.4]").
    *
    * @link    https://tools.ietf.org/html/rfc5321#section-2.3.5
    * @link    http://cbl.abuseat.org/namingproblems.html
    * @return    string
    */
    protected function _get_hostname()
    {
        if (isset($_SERVER['SERVER_NAME']))
        {
            return $_SERVER['SERVER_NAME'];
        }

        return isset($_SERVER['SERVER_ADDR']) ? '['.$_SERVER['SERVER_ADDR'].']' '[127.0.0.1]';
    


The solution was:
PHP Code:
    /**
    * Get Hostname
    *
    * There are only two legal types of hostname - either a fully
    * qualified domain name (eg: "mail.example.com") or an IP literal
    * (eg: "[1.2.3.4]").
    *
    * @link    https://tools.ietf.org/html/rfc5321#section-2.3.5
    * @link    http://cbl.abuseat.org/namingproblems.html
    * @return    string
    */
    protected function _get_hostname()
    {
        if (isset($_SERVER['SERVER_NAME']))
        {
            return $_SERVER['SERVER_NAME'];
        }

        if (isset($_SERVER['SERVER_ADDR'])) {
            return '['.$_SERVER['SERVER_ADDR'].']';
        }

        $hostname gethostname();
        return '['.gethostbyname($hostname).']';
    


And you might ask "why", my answer is because we are running a PHP script code from CLI in remote server. When we try to send an email from localhost the current IP is almost always 127.0.0.1, but from a remote server this snippet code needs to get the public IP address to identify itself in "EHLO" to SMTP data.


RE: Sending multiple emails from my smtp-relay avoiding DoS - luckmoshy - 01-04-2023

of course, you are right since an earlier thread you could not be detected between local and remote by the way that great


RE: Sending multiple emails from my smtp-relay avoiding DoS - InsiteFX - 01-05-2023

Please add an issue report to the CodeIgniter 3 Developers on GitHub.

CodeIgniter 3.x.x Development GitHub