@@ -70,6 +70,7 @@ sub usage {
70
70
71
71
Sending:
72
72
--envelope-sender <str> * Email envelope sender.
73
+ --sendmail-cmd <str> * Command to run to send email.
73
74
--smtp-server <str:int> * Outgoing SMTP server to use. The port
74
75
is optional. Default 'localhost'.
75
76
--smtp-server-option <str> * Outgoing SMTP server option to use.
@@ -262,6 +263,7 @@ sub do_edit {
262
263
my (@suppress_cc );
263
264
my ($auto_8bit_encoding );
264
265
my ($compose_encoding );
266
+ my ($sendmail_cmd );
265
267
# Variables with corresponding config settings & hardcoded defaults
266
268
my ($debug_net_smtp ) = 0; # Net::SMTP, see send_message()
267
269
my $thread = 1;
@@ -309,6 +311,7 @@ sub do_edit {
309
311
" assume8bitencoding" => \$auto_8bit_encoding ,
310
312
" composeencoding" => \$compose_encoding ,
311
313
" transferencoding" => \$target_xfer_encoding ,
314
+ " sendmailcmd" => \$sendmail_cmd ,
312
315
);
313
316
314
317
my %config_path_settings = (
@@ -442,6 +445,7 @@ sub read_config {
442
445
" no-bcc" => \$no_bcc ,
443
446
" chain-reply-to!" => \$chain_reply_to ,
444
447
" no-chain-reply-to" => sub {$chain_reply_to = 0},
448
+ " sendmail-cmd=s" => \$sendmail_cmd ,
445
449
" smtp-server=s" => \$smtp_server ,
446
450
" smtp-server-option=s" => \@smtp_server_options ,
447
451
" smtp-server-port=s" => \$smtp_server_port ,
@@ -1013,16 +1017,19 @@ sub expand_one_alias {
1013
1017
$reply_to = sanitize_address($reply_to );
1014
1018
}
1015
1019
1016
- if (!defined $smtp_server ) {
1020
+ if (!defined $sendmail_cmd && ! defined $ smtp_server ) {
1017
1021
my @sendmail_paths = qw( /usr/sbin/sendmail /usr/lib/sendmail ) ;
1018
1022
push @sendmail_paths , map {" $_ /sendmail" } split /:/, $ENV {PATH };
1019
1023
foreach (@sendmail_paths ) {
1020
1024
if (-x $_ ) {
1021
- $smtp_server = $_ ;
1025
+ $sendmail_cmd = $_ ;
1022
1026
last ;
1023
1027
}
1024
1028
}
1025
- $smtp_server ||= ' localhost' ; # could be 127.0.0.1, too... *shrug*
1029
+
1030
+ if (!defined $sendmail_cmd ) {
1031
+ $smtp_server = ' localhost' ; # could be 127.0.0.1, too... *shrug*
1032
+ }
1026
1033
}
1027
1034
1028
1035
if ($compose && $compose > 0) {
@@ -1502,11 +1509,17 @@ sub send_message {
1502
1509
1503
1510
if ($dry_run ) {
1504
1511
# We don't want to send the email.
1505
- } elsif (file_name_is_absolute($smtp_server )) {
1512
+ } elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server )) {
1506
1513
my $pid = open my $sm , ' |-' ;
1507
1514
defined $pid or die $! ;
1508
1515
if (!$pid ) {
1509
- exec ($smtp_server , @sendmail_parameters ) or die $! ;
1516
+ if (defined $sendmail_cmd ) {
1517
+ exec (" sh" , " -c" , " $sendmail_cmd \"\$ @\" " , " -" , @sendmail_parameters )
1518
+ or die $! ;
1519
+ } else {
1520
+ exec ($smtp_server , @sendmail_parameters )
1521
+ or die $! ;
1522
+ }
1510
1523
}
1511
1524
print $sm " $header \n $message " ;
1512
1525
close $sm or die $! ;
@@ -1602,14 +1615,21 @@ sub send_message {
1602
1615
printf ($dry_run ? __(" Dry-Sent %s \n " ) : __(" Sent %s \n " ), $subject );
1603
1616
} else {
1604
1617
print ($dry_run ? __(" Dry-OK. Log says:\n " ) : __(" OK. Log says:\n " ));
1605
- if (!file_name_is_absolute($smtp_server )) {
1618
+ if (!defined $sendmail_cmd && ! file_name_is_absolute($smtp_server )) {
1606
1619
print " Server: $smtp_server \n " ;
1607
1620
print " MAIL FROM:<$raw_from >\n " ;
1608
1621
foreach my $entry (@recipients ) {
1609
1622
print " RCPT TO:<$entry >\n " ;
1610
1623
}
1611
1624
} else {
1612
- print " Sendmail: $smtp_server " .join (' ' ,@sendmail_parameters )." \n " ;
1625
+ my $sm ;
1626
+ if (defined $sendmail_cmd ) {
1627
+ $sm = $sendmail_cmd ;
1628
+ } else {
1629
+ $sm = $smtp_server ;
1630
+ }
1631
+
1632
+ print " Sendmail: $sm " .join (' ' ,@sendmail_parameters )." \n " ;
1613
1633
}
1614
1634
print $header , " \n " ;
1615
1635
if ($smtp ) {
0 commit comments