]>
git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - scripts/smtpsend
2 #-----------------------------------------------------------------------------
3 # This program gives you low level control over an SMTP conversation.
5 # This program delivers a mail message to an SMTP server. Command line
6 # options tell what server to use and determine the commands this program
7 # sends to it. The program reads the mail message itself from
10 # This program does not generate headers inside the mail message (e.g.
11 # RFC 822 headers). You can use the program 'makemail' to do that.
13 # This program does not extract any envelope information from the mail
14 # message or rewrite the message in any way.
15 #-----------------------------------------------------------------------------
34 if (defined($fromOpt)) {
37 my $user = $ENV{"USER"} || $ENV{"LOGNAME"};
38 if (!defined("$user")) {
39 die("You didn't supply a sender address with " .
40 "--from and I cannot " .
41 "default one because neither USER nor LOGNAME environment " .
44 my $hostname = hostname
;
45 if (defined($hostname)) {
46 $retval = "$user\@$hostname";
56 ##############################################################################
58 ##############################################################################
62 $options{"to"} = []; # Establish as an array reference
74 if ($options{"debug"}) {
78 if (@
{$options{"to"}} == 0) {
79 die("Must specify the recipient email address with --to");
82 my @recipients = @
{$options{"to"}};
83 #print Data::Dumper->Dump([ \@recipients ], [ "recipients" ]);
85 my $sender = getSender
($options{"from"});
87 my $server = $options{"server"} || "localhost";
89 my @smtpOptions = (); # initial value
90 if (defined($options{"hello"})) {
91 push(@smtpOptions, Hello
=> $options{"hello"});
93 if (defined($options{"timeout"})) {
94 push(@smtpOptions, Timeout
=> $options{"timeout"});
96 if ($options{"debug"}) {
97 push(@smtpOptions, Debug
=> 1);
100 my $smtp = Net
::SMTP
->new($server, @smtpOptions);
102 if (!defined($smtp)) {
103 die("Failed to connect to SMTP server at '$server'");
106 if (!$options{"quiet"}) {
107 print("Server at $server identifies as '" . $smtp->domain . "' " .
111 print ("Reading mail message from Standard Input...\n");
114 my $result = $smtp->mail($sender);
116 warn("Failed sending MAIL command. " .
117 "Server says '" . $smtp->message . "'");
120 foreach my $recipient (@recipients) {
121 my $result = $smtp->recipient($recipient);
123 warn("Failed sending RCPT command for '$recipient'. " .
124 "Server says '" . $smtp->message . "'");
132 my @message = <STDIN
>;
134 my $result = $smtp->data(@message);
137 warn("Server rejected message. " .
138 "Server says '" . $smtp->message . "'");
143 if (!$options{"quiet"}) {
145 if (@recipients == 1) {
146 $recipientDesc = $recipients[0];
148 $recipientDesc = scalar(@recipients) . " recipients";
150 print("Message sent to $recipientDesc from $sender.\n");