File: test.pl

package info (click to toggle)
libmail-sendeasy-perl 1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 168 kB
  • ctags: 103
  • sloc: perl: 801; makefile: 3
file content (92 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#########################

###use Data::Dumper ; print Dumper(  ) ;

use Test;
BEGIN { plan tests => 6 } ;

use Mail::SendEasy ;

use strict ;
use warnings qw'all' ;

ok(1);

my ( $host , $user , $pass , $from , $to ) ;

  if ( !$host || !$user || !$pass ) {
    print "\n----------------\n" ;
    print "SMTP SERVER for the tests: " ;
    chomp( $host = <STDIN> ) ;
    print "USERNAME: " ;
    chomp( $user = <STDIN> ) ;
    print "PASSWORD: " ;
    chomp( $pass = <STDIN> ) ;
    print "FROM: " ;
    chomp( $from = <STDIN> ) ;
    print "TO: " ;
    chomp( $to = <STDIN> ) ;
  }
  
  $to ||= $from ;
  
  print "\n----------------\n" ;
  print "SETS:\n" ;
  print "  host: $host\n" ;
  print "  user: $user\n" ;
  print "  pass: $pass\n" ;
  print "  from: $from\n" ;
  print "  to:   $to\n" ;
  print "----------------\n" ;

#########################
if ($host && $from) {

  my $mail = new Mail::SendEasy(
  smtp => $host , 
  user => $user ,
  pass => $pass ,
  ) ;
  
  ok($mail) ;
  
  my $status = $mail->send(
  from    => $from ,
  from_title => 'Perl Test' ,
  to      => $to ,
  subject => "Mail::SendEasy - Perl Test" ,
  msg     => "The Plain Msg..." ,
  html    => "<b>The HTML Msg...</b>" ,
  ) ;
  
  ok($status) ;
  
  if (! $status) { print $mail->error ;}
}
else { print "## Skiped test from 2..3 (need host && from)\n" ;}
#########################
if ( $host && $user && $pass ) {

  print "## AUTH TESTS:\n" ;

  my $smtp = Mail::SendEasy::SMTP->new($host) ;

  ok($smtp) ;
  
  ok( $smtp->auth_types ) ;
  
  if ( $smtp->auth($user , $pass) ) { ok(1) ;}
  else {
    my @response = $smtp->last_response ;
    foreach my $response_i ( @response ) {
      warn("AUTH: $$response_i[0] $$response_i[1]\n") ;
    }
  }

}
else { print "## Skiped test from 4..6 (need host && user && pass)\n" ;}
#########################

print "\nThe End! By!\n" ;

1 ;