-
Notifications
You must be signed in to change notification settings - Fork 7
/
SMTP.rakumod
57 lines (52 loc) · 1.29 KB
/
SMTP.rakumod
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
unit class Net::SMTP:ver<1.2.2>:auth<zef:raku-community-modules>;
has $.server;
has $.port;
has $.debug;
has $.raw;
has $.socket;
has $.tls;
has $.ssl;
has $.plain;
method new(
Str :$server!,
Int :$port = 25,
Bool :$raw,
Bool :$debug,
Str :$hostname,
Mu :$socket = IO::Socket::INET,
Bool :$starttls,
Bool :$ssl,
Bool :$plain
){
my role debug-connection {
method print($string){
my $tmpline = $string.substr(0, *-2);
note '==> '~$tmpline;
nextwith($string);
}
method get() {
my $line = callwith();
note '<== '~$line;
$line
}
};
my $self := self.bless:
:$server, :$port, :$socket, :tls($starttls), :$ssl,
:$plain, :$debug, :$raw;
if $raw {
use Net::SMTP::Raw;
$self does Net::SMTP::Raw;
$self.conn = $socket.defined ?? $socket !! $socket.new(:host($server), :$port);
$self.conn = $self.conn but debug-connection if $debug;
$self.conn.nl-in = "\r\n";
}
else {
use Net::SMTP::Simple;
$self does Net::SMTP::Simple;
$self.hostname = $hostname // $*KERNEL.hostname();
my $started = $self.start;
return $started unless $started;
}
$self
}
# vim: expandtab shiftwidth=4