Thread Versenden von Emails (Net::SMTP) (13 answers)
Opened by styx-cc at 2019-07-31 23:24

styx-cc
 2019-07-31 23:24
#190304 #190304
User since
2006-05-20
533 Artikel
BenutzerIn

user image
Hi Community!

Folgendes Script benutze ich schon lange zum Senden von Benachrichtigungsmails:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
use warnings;
use strict;

use Net::SMTP;


send_mail('hi', 'test-msg', ['stefan@example.com']);

sub send_mail {
        my $sub = shift;
        my $msg = shift;
        my $to  = shift;

        my $pid = fork();

        if ( !defined $pid ) {
            die "Cannot fork: $!";
        }

        elsif ( $pid == 0 ) {
                #child  
                die "Recipients need to be array-ref." unless ref $to eq 'ARRAY';

                my $smtp = Net::SMTP->new("mail.example.com", Port => 587, Debug => 1) or die $!;

                my $from = 'robot@example.com';
                $smtp->starttls( SSL_verify_mode => 0  );
                $smtp->auth('robot@example.com', 'PASS');

                $smtp->mail($from);
                $smtp->to( @$to );

                $smtp->data();
                $smtp->datasend('Date: ' . localtime( time() ) . "\n" );
                $smtp->datasend("From: $from\n");
                $smtp->datasend('To: ' . join(',', @$to) . "\n");
                $smtp->datasend("Subject: $sub\n");
                $smtp->datasend("\n");

                $smtp->datasend("$msg\n\n");

                $smtp->dataend;
                $smtp->quit;

                exit 0;
        }
}


Nun habe ich von Stretch auf Buster migriert und das Senden funktioniert nicht mehr, er sendet kein AUTH mehr und ich kann mir keinen Reim darauf machen.

Funktionierend:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
styx@HermesWWW:~/dev-prod/dev/SMA$ perl SendEmail.pl 
styx@HermesWWW:~/dev-prod/dev/SMA$ Net::SMTP>>> Net::SMTP(3.08_01)
Net::SMTP>>> Net::Cmd(3.08_01)
Net::SMTP>>> Exporter(5.72)
Net::SMTP>>> IO::Socket::IP(0.37)
Net::SMTP>>> IO::Socket(1.38)
Net::SMTP>>> IO::Handle(1.36)
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 220 mail.example.com ESMTP Postfix
Net::SMTP=GLOB(0x55cc2bf21b80)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-mail.example.com
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-PIPELINING
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-SIZE 52428800
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-VRFY
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-ETRN
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-STARTTLS
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-8BITMIME
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250-DSN
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 250 CHUNKING
Net::SMTP=GLOB(0x55cc2bf21b80)>>> STARTTLS
Net::SMTP=GLOB(0x55cc2bf21b80)<<< 220 2.0.0 Ready to start TLS
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> EHLO localhost.localdomain
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-mail.example.com
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-PIPELINING
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-SIZE 52428800
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-VRFY
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-ETRN
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-AUTH PLAIN LOGIN
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-8BITMIME
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250-DSN
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250 CHUNKING
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> AUTH PLAIN df9ib3RAcG9tZXJlcmlnLmRlAHJvYm90JDUvbWVyZXJpZy5kPOI0M0UwM01IcjHgFlO=
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 235 2.7.0 Authentication successful
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> MAIL FROM:<robot@example.com>
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250 2.1.0 Ok
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> RCPT TO:<stefan@example.com>
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250 2.1.5 Ok
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> DATA
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 354 End data with <CR><LF>.<CR><LF>
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> Date: Wed Jul 31 23:18:52 2019
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> From: robot@example.com
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> To: stefan@example.com
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> Subject: hi
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> test-msg
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> .
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 250 2.0.0 Ok: queued as 9F6EC721B52
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)>>> QUIT
Net::SMTP::_SSL=GLOB(0x55cc2bf21b80)<<< 221 2.0.0 Bye



Nicht mehr Funktionierend:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
stefan@dev:~/old-dev/SMA$ perl SendEmail.pl
stefan@dev:~/old-dev/SMA$ Net::SMTP>>> Net::SMTP(3.11)
Net::SMTP>>> Net::Cmd(3.11)
Net::SMTP>>> Exporter(5.73)
Net::SMTP>>> IO::Socket::IP(0.39)
Net::SMTP>>> IO::Socket(1.39)
Net::SMTP>>> IO::Handle(1.39)
Net::SMTP=GLOB(0x556995279648)<<< 220 mail.example.com ESMTP Postfix
Net::SMTP=GLOB(0x556995279648)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x556995279648)<<< 250-mail.example.com
Net::SMTP=GLOB(0x556995279648)<<< 250-PIPELINING
Net::SMTP=GLOB(0x556995279648)<<< 250-SIZE 52428800
Net::SMTP=GLOB(0x556995279648)<<< 250-VRFY
Net::SMTP=GLOB(0x556995279648)<<< 250-ETRN
Net::SMTP=GLOB(0x556995279648)<<< 250-STARTTLS
Net::SMTP=GLOB(0x556995279648)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x556995279648)<<< 250-8BITMIME
Net::SMTP=GLOB(0x556995279648)<<< 250-DSN
Net::SMTP=GLOB(0x556995279648)<<< 250 CHUNKING
Net::SMTP=GLOB(0x556995279648)>>> STARTTLS
Net::SMTP=GLOB(0x556995279648)<<< 220 2.0.0 Ready to start TLS
Net::SMTP::_SSL=GLOB(0x556995279648)>>> EHLO localhost.localdomain
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-mail.example.com
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-PIPELINING
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-SIZE 52428800
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-VRFY
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-ETRN
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-AUTH PLAIN LOGIN
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-8BITMIME
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250-DSN
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250 CHUNKING
Net::SMTP::_SSL=GLOB(0x556995279648)>>> MAIL FROM:<robot@example.com>
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 250 2.1.0 Ok
Net::SMTP::_SSL=GLOB(0x556995279648)>>> RCPT TO:<stefan@example.com>
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 554 5.7.1 <dev.example.com[78.46.xx.xx]>: Client host rejected: Access denied
Net::SMTP::_SSL=GLOB(0x556995279648)>>> DATA
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 554 5.5.1 Error: no valid recipients
Net::SMTP::_SSL=GLOB(0x556995279648)>>> Date: Wed Jul 31 23:19:43 2019
Net::SMTP::_SSL=GLOB(0x556995279648)>>> From: robot@example.com
Net::SMTP::_SSL=GLOB(0x556995279648)>>> To: stefan@example.com
Net::SMTP::_SSL=GLOB(0x556995279648)>>> Subject: hi
Net::SMTP::_SSL=GLOB(0x556995279648)>>> test-msg
Net::SMTP::_SSL=GLOB(0x556995279648)>>> .
Net::SMTP::_SSL=GLOB(0x556995279648)<<< 221 2.7.0 Error: I can break rules, too. Goodbye.
Net::SMTP::_SSL=GLOB(0x556995279648)>>> QUIT


Ab und zu nach dem QUIT noch ein:
Code: (dl )
1
2
Net::SMTP::_SSL: Net::Cmd::_syswrite_with_timeout(): unexpected EOF on command channel: Connection reset by peer at Se
ndEmail.pl line 44.


Vielleicht hat ja jemand einen Lösungsvorschlag oder gar das selbe Problem gehabt, ich habe aktuell nicht mal einen Ansatz außer die Richtung SSL..

Vielen Dank und Lieben Gruß


P.s.: Wäre lieb, wenn jmd. den Beitrag den ich als Gast geschrieben habe entfernen könnte, danke!
Last edited: 2019-07-31 23:31:28 +0200 (CEST)
Pörl.

View full thread Versenden von Emails (Net::SMTP)