diff --git a/config/install/smtp.settings.yml b/config/install/smtp.settings.yml
index 24772f7..0674b8d 100644
--- a/config/install/smtp.settings.yml
+++ b/config/install/smtp.settings.yml
@@ -10,3 +10,4 @@ smtp_fromname: ''
 smtp_allowhtml: ''
 smtp_test_address: ''
 smtp_debugging: false
+prev_mail_system: 'php_mail'
diff --git a/config/schema/smtp.schema.yml b/config/schema/smtp.schema.yml
index 2b0932b..d94e0cd 100644
--- a/config/schema/smtp.schema.yml
+++ b/config/schema/smtp.schema.yml
@@ -38,3 +38,6 @@ smtp.settings:
     smtp_debugging:
       type: boolean
       label: 'Enable debugging'
+    prev_mail_system:
+      type: text
+      label: 'Previous mail system'
diff --git a/smtp.install b/smtp.install
index f97331c..7dd3e40 100644
--- a/smtp.install
+++ b/smtp.install
@@ -9,6 +9,8 @@
  * Implements hook_install().
  */
 function smtp_install() {
+  $mail_config = \Drupal::config('system.mail');
+
   // Setting default config vars.
   \Drupal::service('config.factory')->getEditable('smtp.settings')
     ->set('smtp_on', 0)
@@ -23,6 +25,7 @@ function smtp_install() {
     ->set('smtp_allowhtml', '')
     ->set('smtp_test_address', '')
     ->set('smtp_debugging', 0)
+    ->set('prev_mail_system', $mail_config->get('interface'))
     ->save();
 }
 
diff --git a/src/Form/SMTPConfigForm.php b/src/Form/SMTPConfigForm.php
index fc8c68e..6478386 100644
--- a/src/Form/SMTPConfigForm.php
+++ b/src/Form/SMTPConfigForm.php
@@ -216,6 +216,19 @@ class SMTPConfigForm extends ConfigFormBase {
       ->set('smtp_debugging', $values['smtp_debugging'])
       ->save();
 
+    // Set as default mail system if module is enabled.
+    if ($config->get('smtp_on')) {
+      if ($mail_config['default'] != 'SMTPMailSystem') {
+        $config->set('prev_mail_system', $mail_system);
+      }
+      $mail_system['default'] = 'SMTPMailSystem';
+      $mail_config->set('interface', $mail_system)->save();
+    }
+    else {
+      $mail_system = $config->get('prev_mail_system');
+      $mail_config->set('interface', $mail_system)->save();
+    }
+
     // If an address was given, send a test e-mail message.
     if ($test_address = $values['smtp_test_address']) {
       $params['subject'] = t('Drupal SMTP test e-mail');
