Skip to content

Instantly share code, notes, and snippets.

@ysasaki
Created May 30, 2013 07:50
Show Gist options
  • Save ysasaki/5676334 to your computer and use it in GitHub Desktop.
Save ysasaki/5676334 to your computer and use it in GitHub Desktop.
use utf8;
use strict;
use warnings;
use Test::More;
use Test::Name::FromLine;
use Test::TCP;
use Net::SMTP;
use Net::SMTP::Server;
use Net::SMTP::Server::Client;
my $server = Test::TCP->new(
code => sub {
my $port = shift;
my $smtp = Net::SMTP::Server->new('localhost', $port);
while ( my $conn = $smtp->accept() ) {
my $client = Net::SMTP::Server::Client->new($conn);
$client->process || next;
like $client->{MSG}, qr{http://example\.com/clickme\?s=abcdefg};
}
}
);
my $smtp = Net::SMTP->new(
'localhost',
Port => $server->port,
Timeout => 10,
);
my $data = <<'EOM';
From: [email protected]
To: [email protected]
http://example.com/clickme?s=abcdefg
EOM
$smtp->mail('[email protected]');
$smtp->to('[email protected]');
$smtp->data;
$smtp->datasend($data);
$smtp->dataend;
$smtp->quit;
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment