How can I activate the "Disable Outbound email" option or change the SMTP server address with only an SQL Query?

(My use case is when I copy live data to a test environment, I obviously want to make sure no real emails are sent from the test environment!)



In civicrm.settings.php, add the following:

define('CIVICRM_MAIL_LOG', 1);

This will route all email to files/civicrm/ConfigAndLog/mail (Drupal) or media/civicrm/ConfigAndLog (Joomla).

You can also specify:

define('CIVICRM_MAIL_LOG', "your_file_path");

to set a specific output file.

See https://wiki.civicrm.org/confluence/display/CRMDOC/Debugging+for+developers.

Another option is to perform the following queries to kill any scheduled or queued mail:

UPDATE `civicrm_mailing_job` SET `status`= 'Complete' WHERE `status` IN ('Scheduled', 'Running', 'Paused')
DELETE FROM `civicrm_mailing_spool` WHERE 1
| improve this answer | |
  • Thanks for the mail log! Will test soon. Good call on the civicrm_mailing_spool trick, tho that only stops existing emails, and I'd like to change the settings to also stop any new emails that might be made in testing. – James Jun 15 '16 at 14:43
  • Yes civicrm_mail_log is an excellent solution! – KarinG - Semper IT Jun 15 '16 at 16:18

You can use https://www.drupal.org/project/civicrm_reroute_email module and enable it on test env, which will reroute all CiviCRM emails to the specified email address. This will work with Drupal.

| improve this answer | |

Got it. To see current value, run:

select * from civicrm_setting where name='mailing_backend';

Because it's PHP serialise format, there is no easy change to change one value only! Sigh. I would recommend setting your app to dummy variables, then running the above to get the current value, then sticking that in a update statement to give you something like:

update civicrm_setting set value='a:10:{s:15:"outBound_option";s:1:"0";s:5:"qfKey";s:37:"xxxxxxxxxxxxx";s:8:"entryURL";s:131:"https://xxxxxxxxxxxx";s:13:"sendmail_path";s:0:"";s:13:"sendmail_args";s:0:"";s:10:"smtpServer";s:9:"localhost";s:8:"smtpPort";s:2:"25";s:8:"smtpAuth";s:1:"0";s:12:"smtpUsername";s:0:"";s:12:"smtpPassword";s:0:"";}' where name='mailing_backend';

Hopefully, in future that update statement will set your SMTP settings back to dummy variables!

| improve this answer | |
  • Could be make with a regex to avoid change the another params (in mariadb works, not sure mysql) sql UPDATE civicrm_setting SET value = REGEXP_REPLACE(value,'outBound_option\";s:1:\"[0-9]','outBound_option\";s:1:\"5') WHERE name = "mailing_backend"; – rubofvil Aug 19 at 12:10

I created a small drush plugin that just does this. It also disables the standard drupal email. function drush_modulename_commandname(){ drush_print('Disabling outgoing email - drupal & civi'); civicrm_initialize(); $result = civicrm_api3('Setting', 'create', array( 'mailing_backend' => array('outBound_option'=> CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB), )); if($result["is_error"]){ drush_log('CiCRM Error'.$result['error_message'],'ok'); } variable_set('mail_system',array ( 'default-system' => 'TestingMailSystem', 'mimemail' => 'TestingMailSystem', )); drush_print('Done'); } Information how to create drush commands can be found on http://docs.drush.org/en/master/commands/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.