Avatar of Rawand Amin
Rawand Amin
 asked on

add a 1000 ms delay after each sending email operation

Dears,

My Sendmail SMTP-relay experiencing problem as user sends email to over 70 users.  the error message on sendmail log is (Sending error 421 4.7.0 Temporary System Problem), however the return fail message is (reason: 530 5.7.0 Must issue a STARTTLS command first).  

About 60 users get the email out of 70,  I don't know what is the problem.   I browsed internet, some peole suggest to delay sending emails by 1000ms between each email.  some other indcates the problem is with (using plain autentication).  I basically don't know how to fix this:

Using following services:
SMTP-relay: installed on Linux system
user send email through SMTP-relay installed on the same server.

if you require other information please let me know.

your help is highly appreciated

thanks,




Thanks
PHPLinux

Avatar of undefined
Last Comment
Rawand Amin

8/22/2022 - Mon
arnold

From which system are you getting this error?
When do you get this message?
If this is within PHP, why are you using the SMTP method within PHP versus using the direct injection method?
Do not define SMTP within php.ini but use sendmail_path=/usr/sbin/sendmail -oi -t?

This will have PHP submitting the message to sendmail without the SMTP interaction.

This is similar to
echo "To: <emailaddress>
From: <sender>
Subject: direct injection message

This is the message Body(message)
" | /usr/sbin/sendmail -oi -t

the -t tells sendmail to look for the destination of the message within the data TO, Cc and Bcc (Bcc will be stripped after processing.

If the error is within the sendmail log, a 4xx error means that sendmail will retry sending this message at a later time.
Double check what your queue lifetime is within sendmail, to make sure it is at least one day which means it will attempt to transmit messages to which it gets 4xx (temporary error) for the queue lifetime before giving up and treating the temporary error as a permanent one.
Ray Paseur

Are you using PHP for this?  If so, please show us the PHP scripts that are in play.  The SSCCE is an incredibly important concept when you're trying to get help with any problem.

If you want to make a PHP script pause for 1000ms, run this instruction: sleep(1);
Rawand Amin

ASKER
First of all, I would like to thank you for your help.

Attached is the php file that i believe the system uses to send email.

Allow me to provide you with more information about what I am using:
Moodle service used in our university to support students and facutlies.  Moodle uses its own PHP file to send email through Sendmail (SMTP-Rela) hosted on the same network but different server.  therefore we do not touch the php.ini file.

the only configuration i make on Moodle side is to tell moodle to send email through our SMTP-Relay.
There are other files named as follow:
class.smtp.php
moodle_phpmailer.php

Error message appear on Linux SMTP-relay server (Sending error 421 4.7.0 Temporary System Problem),

Sent to web administrator automatically from Gmail (no-reply@ourdomain.) (reason: 530 5.7.0 Must issue a STARTTLS command first).
full detail:
From: Mail Delivery Subsystem <no-reply@ourdomain> [u]Gmail server[/u]
Date: Sun, Oct 16, 2016 at 9:02 PM
Subject: Returned mail: see transcript for details
To: webadmin@gmaildomain

The original message was received at Sun, 16 Oct 2016 13:30:06 +0300
from moodle.ourdomain [SERVERIP]

   ----- The following addresses had permanent fatal errors -----
<user@ourdomain>
    (reason: 530 5.7.0 Must issue a STARTTLS command first. qq7sm4465619wjc.30 - gsmtp)

Open in new window


eventually the message has not received to end user.
class.phpmailer.php
Your help has saved me hundreds of hours of internet surfing.
fblack61
Ray Paseur

STARTTLS is an extension to plain text communication protocols, which offers a way to upgrade a plain text connection to an encrypted (TLS or SSL) connection instead of using a separate port for encrypted communication.

http://en.wikipedia.org/wiki/STARTTLS

You may need to add ssl:// as the protocol

Even if you're not using GroupMail, this link may show us a good idea.
http://group-mail.com/email-error-codes/server-says-530-5-7-0-must-issue-starttls-command-first/

This also looks like something easy to try:
https://forums.zoho.com/topic/sending-failed%3B-reason%3A530-5-7-0-must-issue-a-starttls-command-first-6-12-2009
Julian Hansen

If you use sleep() also look at set_time_limit() to avoid your script timing out.

The rationale behind the 1000ms delay is that some ISP's have a throttle on how many emails you can send in a time period - if you exceed that they block you.

Have you considered outsourcing sending of emails to a bulk email provider. They handle all of this for you.
arnold

The confusing thing you say you have an SMTP-relay, to which server is this SMTP-RELAY, relays?
The error you have deals with an expected mechanism.
Often, smtp-relay means that your server handles the message and then sends it through to you ISP to handle the disposition.

Your relay might be misconfigured to direct the email to a server that is not the public destination of .... and thus requires additional security features such that you would need to configure your SMTP server, sendmail to handle outgoing message.
i.e. you configured your smtp-relay to go through a specific server including an off port (not 25).......
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
skullnobrains

i don't believe the sleep would help with these errors.

actually having these errors is inconsistent with the fact that some of the email manages through, except if you're doing some weird stuff such as manually relaying to gmail's submission servers rather than the regular smtp...

if you're relaying through sendmail/postfix/exim or whatever relay you installed locally, it's logs would be welcome
Rawand Amin

ASKER
I have taken Ray Paseur into concentration, and re-configure SSL certification on the same server, as highlighted below.  I am waiting for someone to send bunch of and have a result.

I you know any command in linux sendmail that would enable me to send a big number of email to test the system please let me know.

define(`SMART_HOST', `smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl

define(`CERT_DIR', `/etc/mail/certs')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confCACERT', `CERT_DIR/ca-bundle.crt')dnl
define(`confCRL', `CERT_DIR/ca-bundle.crt')dnl
define(`confSERVER_CERT', `CERT_DIR/sendmail.pem')dnl
define(`confSERVER_KEY', `CERT_DIR/sendmail.pem')dnl
define(`confCLIENT_CERT', `CERT_DIR/sendmail.pem')dnl
define(`confCLIENT_KEY', `CERT_DIR/sendmail.pem')dnl
dnl #define(`confAUTH_OPTIONS', `A p')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

Open in new window





Thanks all for your help
arnold

Sendmail need not be enable to send massive amount of emails. You are configuring your sendmail as to relay through port 587 which is configured with different requirements. The additions you made enable features on your site, it does not force your sendmail client side interaction with gmail to STARTTLS during the connection as the error clearly states is the reason for the message exchange failure.

Do you have your outgoing port 25 blocked? If so, check with your ISP as to their Mail server through which you would configure your sendmail server to relay.
instead of smtp.gmail.com you would have smtp.myispprovider.com .......
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
skullnobrains

seems good. if you don't see errors any more, we can probably assume that the previous config led to errors but sendmail was able to interpret them and send the mail nevertheless. ddoes not matter anyway if you don't have them.

beware that gmail as most smtp providers applies rather strict policies regarding outgoing email and may decide to reject or discard yours very soon if you send more than a few dozens a day, no mentioning content filtering. you may consider other setups. if port 25 is not blocked and your ip range belongs to you or is configured with proper ptrs, you can use direct delivery.

as far as gmail goes, you can throttle delivery in sendmail. use rules such as do not send more than 1 mail per minute and no more than 20 per hour... note that i used arbitrary values that should work with gmail ( or would recently ) but i don't know ( and gmail does not communicate them ) the actual rules in use ; and they are subject to change without warning.
Rawand Amin

ASKER
Thanks