docs
[mirrors/Programs.git] / perl / smtp.pl
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use IO::Socket::INET;
5 use Net::SMTP;
6
7 my $netdns = eval 'use Net::DNS';
8 if($netdns) { use Net::DNS };
9
10 my $from='harvie@harvie.cz';
11 my $rcpt='harvie@email.cz';
12 my $subj='Subj3ct';
13 my $mesg='H3ll0 Dolly!';
14
15 my @rcpts = split('@', $rcpt);
16
17
18 if($netdns) {
19 my $preference = -1;
20 my $xchg;
21 foreach(mx($rcpts[1])) {
22 if($_->preference > $preference) {
23 $preference = $_->preference;
24 $xchg = $_->exchange;
25 }
26 }
27 } else {
28 #get mx without Net::DNS
29 foreach(split("\n", qx{ bash -c "host -t mx email.cz | cut -d ' ' -f 7" })) {
30 chop($_);
31 print "mx: $_\n";
32 }
33 }
34
35
36 my $smtp = Net::SMTP->new('mx50.seznam.cz', ( debug => 1));
37
38 $smtp->mail($from);
39 $smtp->to($rcpt);
40
41 $smtp->data();
42 $smtp->datasend("Subject: $subj\n");
43 $smtp->datasend("From: $from\n");
44 $smtp->datasend("To: $rcpt\n");
45 $smtp->datasend("\n");
46 $smtp->datasend("$mesg\n");
47 $smtp->dataend();
48 $smtp->quit;
49
This page took 0.282988 seconds and 4 git commands to generate.