|
1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 #!/usr/bin/perl |
|
17 |
|
18 |
|
19 use strict; |
|
20 use IO::Socket; |
|
21 |
|
22 |
|
23 if(scalar @ARGV !=3) { |
|
24 die "syntax <smtp host> <username> <rfc file>"; |
|
25 } |
|
26 |
|
27 my $host=@ARGV[0]; |
|
28 my $username=@ARGV[1]; |
|
29 |
|
30 open RFC,"@ARGV[2]" or die "Couldn't open @ARGV[2]: $@"; |
|
31 my @rfcfile = <RFC>; |
|
32 close RFC; |
|
33 |
|
34 my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => 25, Proto => "tcp", Type => SOCK_STREAM) or die "Couldn't connect to $host : $@\n"; |
|
35 |
|
36 |
|
37 my $welcome = <$socket>; |
|
38 print "<< $welcome"; |
|
39 |
|
40 sendWait($socket,"HELO [127.0.0.1]"); |
|
41 sendWait($socket,"RSET"); |
|
42 sendWait($socket,"MAIL FROM:<$username>"); |
|
43 sendWait($socket,"RCPT TO:<$username>"); |
|
44 sendWait($socket,"DATA"); |
|
45 |
|
46 |
|
47 foreach my $line (@rfcfile) { |
|
48 chomp $line; |
|
49 sendNoWait($socket,$line); |
|
50 } |
|
51 |
|
52 sendWait($socket,"."); |
|
53 |
|
54 print $socket "QUIT\r\n"; |
|
55 print ">> QUIT\n"; |
|
56 close($socket); |
|
57 |
|
58 exit; |
|
59 |
|
60 sub sendWait($$) |
|
61 { |
|
62 my $socket; |
|
63 my $line; |
|
64 ($socket,$line) = @_; |
|
65 |
|
66 print $socket "$line\r\n"; |
|
67 print ">> \"$line\"\n"; |
|
68 my $result; |
|
69 chomp ($result = <$socket>); |
|
70 print "<< $result\n"; |
|
71 } |
|
72 |
|
73 |
|
74 sub sendNoWait($$) |
|
75 { |
|
76 my $socket; |
|
77 my $line; |
|
78 ($socket,$line) = @_; |
|
79 |
|
80 print $socket "$line\r\n"; |
|
81 print ">> \"$line\"\n"; |
|
82 } |
|
83 |