Commit b4ce44df authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3274465 by AdamPS: Add Sendmail transport

parent 54baef12
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies: {  }
id: native
label: Native
plugin: native
configuration: {  }
id: sendmail
label: Sendmail
plugin: sendmail
configuration:
  query:
    command: ''
+1 −1
Original line number Diff line number Diff line
default_transport: native
default_transport: sendmail
+4 −0
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ class TransportForm extends EntityForm {
      '#description' => $definition['description'] ?? '',
    ];

    $form['warning'] = [
      '#markup' => $definition['warning'] ?? '',
    ];

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
+8 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class DsnTransport extends TransportBase {
      '#type' => 'textfield',
      '#title' => $this->t('DSN'),
      '#maxlength' => 255,
      '#default_value' => $this->configuration['dsn'] ?? '',
      '#default_value' => $this->configuration['dsn'],
      '#description' => $this->t('DSN for the Transport, see <a href=":docs">documentation</a>.', [':docs' => static::DOCS_URL]),
      '#required' => TRUE,
    ];
@@ -48,8 +48,14 @@ class DsnTransport extends TransportBase {
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    $dsn = $form_state->getValue('dsn');
    if (parse_url($dsn, PHP_URL_SCHEME) == 'sendmail') {
      // Don't allow bypassing of the checks done by the Sendmail transport.
      $form_state->setErrorByName('dsn', $this->t('Use the Sendmail transport.'));
    }

    try {
      Transport::fromDsn($form_state->getValue('dsn'));
      Transport::fromDsn($dsn);
    }
    catch (\Exception $e) {
      $form_state->setErrorByName('dsn', $this->t('Invalid DSN.'));
+2 −9
Original line number Diff line number Diff line
@@ -11,13 +11,12 @@ use Drupal\symfony_mailer\TransportPluginInterface;
 * @MailerTransport(
 *   id = "native",
 *   label = @Translation("Native"),
 *   description = @Translation("Use the sendmail binary and options configured in the sendmail_path setting of php.ini."),
 *   warning = @Translation("<b>NOT RECOMMENDED, prefer Sendmail). If php.ini uses the sendmail -t command, you won't have error reporting and Bcc headers won't be removed."),
 * )
 */
class NativeTransport extends TransportBase {

  // @todo Maybe should override the options to pass -bs.
  // @see https://swiftmailer.symfony.com/docs/sending.html

  /**
   * {@inheritdoc}
   */
@@ -33,12 +32,6 @@ class NativeTransport extends TransportBase {
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
Loading