Created
December 27, 2011 08:18
-
-
Save jrockway/1523011 to your computer and use it in GitHub Desktop.
Sending a transcript to a SMTP server nicely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature ':5.10'; | |
use autodie qw/open/; | |
my $file = shift; | |
open my $fh, '<', $file; | |
$| = 1; | |
my $seen_data = 0; | |
outer: while(<>){ | |
print {*STDERR} "< $_"; | |
my $line; | |
inner: while(1){ | |
$line = <$fh>; | |
next outer unless defined $line; | |
chomp $line; | |
print {*STDERR} "> $line\n"; | |
print "$line\r\n"; | |
last inner unless $seen_data; | |
} | |
$seen_data = $line eq 'DATA'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HELO snowball2.jrock.us | |
MAIL FROM: [email protected] | |
RCPT TO: [email protected] | |
DATA | |
Hello there. | |
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[~] 0 (jon@snowball2) | |
$ socat system:'perl play.pl script' tcp-connect:itchy.internal:25 | |
< 220 itchy.jrock.us ESMTP Exim 4.72 Tue, 27 Dec 2011 02:16:38 -0600 | |
> HELO snowball2.jrock.us | |
< 250 itchy.jrock.us Hello snowball2.internal [10.0.0.5] | |
> MAIL FROM: [email protected] | |
< 250 OK | |
> RCPT TO: [email protected] | |
< 250 Accepted | |
> DATA | |
< 354 Enter message, ending with "." on a line by itself | |
> Hello there. | |
> . | |
< 451 Temporary local problem - please try later | |
^C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment