How to stop (Cron Daemon) sending multiple emails? - email

I'm a newbie in server administration (centos 7) and have a problem with email notifications from the cron. There is 1 cron job.
15 * * * * user cd /var/www/domain/public_html/cron && php -d error_reporting="E_ALL & ~E_NOTICE" cron.php
and I set MAILTO in order to be notified about errors. But cron daemon sends me multiple emails every hour or two (also with previous cron errors). Then I wanted to disable email notifications completely so set MAILTO="" but still receiving messages. Probably there is a problem with mail or cron log.
Permission denied after trying to clear maillog.
sudo > /var/log/maillog
Any suggestion what to do in order to receive only one email for the cron job?

Related

Why Magento send newsletter emails to all subscribers one time, not every minute

Magento newsletter cron job work sending newsletter mail only one time. But "cron_schedule" table update newsletter records with success status every minute. I want to send newsletter email by scheduled time. How can i fix it? Please guide me...
Here's how:
Choose the correct timezone to solve the timing issue as follow.
Stores-> Configuration -> General -> General -> Locale Options -> Timezone
You have to set Cronjob to send the newsletter automatically at a scheduled time or you can manually run this command to run cron manually:
php bin/magento cron:run
For more details please visit the below link: https://www.mageworx.com/wiki/cat/magento-2-email-newsletter/
Note: I had to install the SMTP extension (https://www.mageplaza.com/magento-2-smtp/) to send emails from my local host.

how to stop postfix MAILER-DAEMON emails

I am running Ubuntu 12.04 with Postfix
Late yesterday, I added a package (ispconfig3) that modified my postfix configuration and also added an entry to the root crontab that was invoking a script.
At around 11PM last night, I uninstalled that package and went to bed. The uninstall deleted the script and it's directory ok. But it did not clean up the crontab entry.
Since cron had trouble invoking the script, it sent root#xx.org an email. But ispconfig3 had modified my postfix configuration, therefore there is no mail transport capability. So a MAILER-DAEMON email was placed in the mail queue.
Overnight, (I'm guessing here!) cron wakes up every minute and tries to do the same thing. So by 7:00AM there are now 1100+ emails in the mail queue. But since postfix is messed up, I can't see them.
At around 8:00ish I realize that something is wrong with my email set up. I check postfix configuration, backout the changes and now I can get emails ok. I can send them, receive them, etc.
Then the flurry of emails start. Every minute or so, I get around 30 MAILER-DAEMON emails indicating that cron couldn't invoke the script. I check
sudo crontab -l
see the stale command for the non-existing script. I clear it out:
sudo crontab -e
I expect the emails to stop.
They don't.
In fact, every minute they seem to be increasing in number. I then spend a few hours looking at a ton of configuration files to try to figure out what is going on. By 11:00ish or so, it's up to 50+ emails coming in every minute.
I finally realized that this stream of emails was occurring because of the failures that occurred the night before and that it was going to go on for 7 days. The "7d" comes from a postfix configuration setting. (BTW I changed that to be "2d" i.e. only a couple of hours).
In any case, I solved it. I'm adding this post so others can save themselves some time. See below.
Finally hit on the idea to look at the mail queue.
A bit of googling and I found this site:
https://www.garron.me/en/linux/delete-purge-flush-mail-queue-postfix.html
I tried
postqueue -p
which listed all of the "(mail transport unavailable)" emails:
... snip ...
-- 1104 Kbytes in 1185 Requests.
I then did:
postqueue -f # this flushes the mail queue
postqueue -p
Mail queue is empty
And all of a sudden email flurry ended.
Note: the website above said to use:
postfix -f
that did not work for me. A bit of googling found the postqueue command.
Another note: I was worried there were emails in that mail queue that were not "mail transport unavailable", so I double checked all 1185 emails to ensure it was ok to purge them.

magento new order send mail not work

magento can send new user mail confirmation, newsletter subscription, invoice and shipment success but can't send new order mail and send order email to customer in admin panel.
in database core_email_queue is full of not sent emails
also i did:
sudo crontab -u www-data -e
and add:
* * * * * /bin/sh /home/salar/public_html/cron.sh
this is my AOE Scheduler:
http://i.stack.imgur.com/OiYcw.png
As of magento 1.9, emails are queued up and are sent via the cron job. If you haven't set this up, you can manually run it by pointing your browser to the file, e.g. http://www.yoursite/cron.php . After you run this, you should receive your emails
The extension AOE_Scheduler can help you in confirming that your Magento cronjob has been configured correctly and is running.

Magento Cart, Newsletter

Magento ver. 1.7.0.0
We are currently using Magento and want to send Newsletters out. It has this build in. We have created templates and then when it gets moved into the queue it sticks there and does not get sent out at the appropriate time. There is no other way of sending the newsletter out immediately and there are no error messages to give you a clue as to why the situation has arisen.
Has anyone come across this and found a fix?
You need to enable cron for scheduled tasks in Magento. Login to your server in ssh (putty), open your crontab;
crontab -e
and add this line to it;
*/5 * * * * php -f /path/to/magento/shell/cron.php
Obviously change /path/to/magento/ to the actual path on the server.
You can now also enable log cleaning in admin which sheds alot of db records which slows Magento down.
Hope this helps
T

conditionally sending cron job emails

I'm not even sure if what I want is possible, but I'd like to run a Cron job where an email is only sent in certain conditions. I know that you can prevent mail from being sent at all by setting MAILTO to an empty string in the crontab file, but I've searched in several different ways, and can't find anything about sending email conditionally. My end goal is to run a Cron job that periodically checks whether the webserver is running, and if not, restart it. I only want an email if the webserver has to be restarted. I'm writing my Cron jobs in Perl. Is there a Perl command I can use within the job script that will disable the email in certain cases? Thanks for any help you can give me.
Cronjobs will send emails if the command you are running generate output. If you write your script to only send output to STDERR/STDOUT when you want an email, that should accomplish your goal.
There are 2 possibilities to send mails from cron jobs:
From program, that has been started by cron daemon,
From UNIX/Linux mechanism, that can send mail, if a program, that has been started as a cron job, has written something to STDOUT or STDERR.
I don't recommend to use the 2nd possibility. It is inflexible. You can't send mails to different recipients, depending on what alert has happened.
Usage of the 2nd way is rather a bad design. Cron jobs should redirect all their stdout and stderr to an idividual for every cron job log file for possible troubleshooting.
Perl possesses perfect possibilities to send mails, e.g. using MIME::Lite module.
This module is not a core one, so that you might should request sysadmin to install this module, if it's not available.
If you will use the 1st way, then your issue is easy to solve using Perl logic: just send the required mail from your Perl program after this program restarted the web server.