docs
[mirrors/Programs.git] / perl / smtp.pl
CommitLineData
21c4e167
H
1#!/usr/bin/env perl
2use strict;
3use warnings;
4use IO::Socket::INET;
5use Net::SMTP;
6
7my $netdns = eval 'use Net::DNS';
8if($netdns) { use Net::DNS };
9
10my $from='harvie@harvie.cz';
11my $rcpt='harvie@email.cz';
12my $subj='Subj3ct';
13my $mesg='H3ll0 Dolly!';
14
15my @rcpts = split('@', $rcpt);
16
17
18if($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
36my $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.16083 seconds and 4 git commands to generate.