File: 02_smtp.t

package info (click to toggle)
libnet-sslglue-perl 1.058-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 825; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download | duplicates (4)
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
50
51
52
53
54
55
56
57
58
59
60
61

use strict;
use warnings;

BEGIN {
	eval "use Net::SMTP";
	if ( $@ ) {
		print "1..0 # no Net::SMTP\n";
		exit
	}
}

use Net::SSLGlue::SMTP;

my $capath = '/etc/ssl/certs/'; # unix?
-d $capath or do {
	print "1..0 # cannot find system CA-path\n";
	exit
};

# first try to connect w/o smtp
# plain
diag( "connect inet to mail.gmx.net:25" );
IO::Socket::INET->new( 'mail.gmx.net:25' ) or do {
	print "1..0 # mail.gmx.net:25 not reachable\n";
	exit
};

# ssl to the right host
diag( "connect ssl to mail.gmx.net:465" );
IO::Socket::SSL->new( 
	PeerAddr => 'mail.gmx.net:465',
	SSL_ca_path => $capath,
	SSL_verify_mode => 1,
	SSL_verifycn_scheme => 'smtp' 
) or do {
	print "1..0 # mail.gmx.net:465 not reachable with SSL\n";
	exit
};


print "1..3\n";

# first direct SSL
my $smtp = Net::SMTP->new( 'mail.gmx.net', 
	SSL => 1, 
	SSL_ca_path => $capath,
);
print $smtp ? "ok\n" : "not ok # smtp connect mail.gmx.net\n";

# then starttls
$smtp = Net::SMTP->new( 'mail.gmx.net' );
my $ok = $smtp->starttls( SSL_ca_path => $capath );
print $ok ? "ok\n" : "not ok # smtp starttls mail.gmx.net\n";
# check that we can talk on connection
print $smtp->quit ? "ok\n": "not ok # quit failed\n";


sub diag { 
	#print STDERR "@_\n" 
}