64
--smtp-pass <str> * Password for SMTP-AUTH; not necessary.
65
--smtp-encryption <str> * tls or ssl; anything else disables.
66
--smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
67
+ --smtp-domain <str> * The domain name sent to HELO/EHLO handshake
68
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
69
70
Automating:
132
my $have_mail_address = eval { require Mail::Address; 1 };
133
my $smtp;
134
my $auth;
135
+my $mail_domain_default = "localhost.localdomain";
136
+my $mail_domain;
137
138
sub unique_email_list(@);
139
sub cleanup_compose_files();
277
"smtp-ssl" => sub { $smtp_encryption = 'ssl' },
278
"smtp-encryption=s" => \$smtp_encryption,
279
"smtp-debug:i" => \$debug_net_smtp,
280
+ "smtp-domain:s" => \$mail_domain,
281
"identity=s" => \$identity,
282
"annotate" => \$annotate,
283
"compose" => \$compose,
838
839
}
840
841
+# Returns the local Fully Qualified Domain Name (FQDN) if available.
842
+#
843
+# Tightly configured MTAa require that a caller sends a real DNS
844
+# domain name that corresponds the IP address in the HELO/EHLO
845
+# handshake. This is used to verify the connection and prevent
846
+# spammers from trying to hide their identity. If the DNS and IP don't
847
+# match, the receiveing MTA may deny the connection.
848
+#
849
+# Here is a deny example of Net::SMTP with the default "localhost.localdomain"
850
+#
851
+# Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain
852
+# Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host
853
+#
854
+# This maildomain*() code is based on ideas in Perl library Test::Reporter
855
+# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
856
+
857
+sub maildomain_net
858
+{
859
+ my $maildomain;
860
+
861
+ if (eval { require Net::Domain; 1 }) {
862
+ my $domain = Net::Domain::domainname();
863
+ $maildomain = $domain
864
+ unless $^O eq 'darwin' && $domain =~ /\.local$/;
865
+ }
866
+
867
+ return $maildomain;
868
+}
869
+
870
+sub maildomain_mta
871
+{
872
+ my $maildomain;
873
+
874
+ if (eval { require Net::SMTP; 1 }) {
875
+ for my $host (qw(mailhost localhost)) {
876
+ my $smtp = Net::SMTP->new($host);
877
+ if (defined $smtp) {
878
+ my $domain = $smtp->domain;
879
+ $smtp->quit;
880
+
881
+ $maildomain = $domain
882
+ unless $^O eq 'darwin' && $domain =~ /\.local$/;
883
+
884
+ last if $maildomain;
885
+ }
886
+ }
887
+ }
888
+
889
+ return $maildomain;
890
+}
891
+
892
+sub maildomain
893
+{
894
+ return maildomain_net() || maildomain_mta() || $mail_domain_default;
895
+}
896
+
897
# Returns 1 if the message was sent, and 0 otherwise.
898
# In actuality, the whole program dies when there
899
# is an error sending a message.
996
if ($smtp_encryption eq 'ssl') {
997
$smtp_server_port ||= 465; # ssmtp
998
require Net::SMTP::SSL;
939
- $smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);
999
+ $mail_domain ||= maildomain();
1000
+ $smtp ||= Net::SMTP::SSL->new($smtp_server,
1001
+ Hello => $mail_domain,
1002
+ Port => $smtp_server_port);
1003
}
1004
else {
1005
require Net::SMTP;
1006
+ $mail_domain ||= maildomain();
1007
$smtp ||= Net::SMTP->new((defined $smtp_server_port)
1008
? "$smtp_server:$smtp_server_port"
1009
: $smtp_server,
1010
+ Hello => $mail_domain,
1011
Debug => $debug_net_smtp);
1012
if ($smtp_encryption eq 'tls' && $smtp) {
1013
require Net::SMTP::SSL;
1030
die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ",
1031
"VALUES: server=$smtp_server ",
1032
"encryption=$smtp_encryption ",
1033
+ "maildomain=$mail_domain",
1034
defined $smtp_server_port ? "port=$smtp_server_port" : "";
1035
}
1036