Volgens het volgende cppsocket voorbeeld heb ik een programmatje gemaakt wat met een mailserver communiceert:
TCP Client Example
Als ik de commando's in telnet intik gaat het gewoon goed... maar de output van het programma is:
\r\n - \n\r - \r - \n ... allemaal achteraan de string, werkt niet.
Wat half werkt, is vooraan de string \n bij elke regel... dan krijg ik maar 1 keer (500 5.5.1 Command unrecognized: "") en wordt het mailtje wel goed verstuurd.
Heeft iemand een idee wat ik fout doe? Of zit de fout in cppsocket lib.?
TCP Client Example
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #include <iostream> #include <tcpclient.h> #include <address.h> #include <string> using namespace std; int main(int argc, char *argv[]) { string smtpReply; try { CPPSocket::TCPClient smtpConnection; CPPSocket::Address host("127.0.0.1",25,false); smtpConnection.connect(host); smtpConnection >> smtpReply; cout << "1 " << smtpReply; smtpConnection << "HELO mydomain.nl\r\n"; smtpConnection >> smtpReply; cout << "2 " << smtpReply; smtpConnection << "MAIL FROM: <from@mydomain.nl>\r\n"; smtpConnection >> smtpReply; cout << "3 " << smtpReply; smtpConnection << "RCPT TO: <to@mydomain.nl>\r\n"; smtpConnection >> smtpReply; cout << "4 " << smtpReply; smtpConnection << "DATA\r\n"; smtpConnection >> smtpReply; cout << "5 " << smtpReply; smtpConnection << "lalala\n.\r\n"; smtpConnection >> smtpReply; cout << "6 " << smtpReply; smtpConnection.disconnect(); } catch(CPPSocket::Exception &error) { cerr << error.getMessage() << endl; exit(1); } return 0; } |
Als ik de commando's in telnet intik gaat het gewoon goed... maar de output van het programma is:
Het heeft wat met de line breaks te maken... ik heb ALLES geprobeerd...1 220 mailerserver ESMTP Sendmail 8.12.8/8.12.8; Tue, 28 Oct 2003 12:06:13 +0100
2 250 mailerserver Hello mydomain.nl [127.0.0.1], pleased to meet you
3 500 5.5.1 Command unrecognized: ""
4 500 5.5.1 Command unrecognized: ""
5 500 5.5.1 Command unrecognized: ""
6 500 5.5.1 Command unrecognized: ""
500 5.5.1 Command unrecognized: "."
\r\n - \n\r - \r - \n ... allemaal achteraan de string, werkt niet.
Wat half werkt, is vooraan de string \n bij elke regel... dan krijg ik maar 1 keer (500 5.5.1 Command unrecognized: "") en wordt het mailtje wel goed verstuurd.
Heeft iemand een idee wat ik fout doe? Of zit de fout in cppsocket lib.?
[ Voor 12% gewijzigd door Akerboom op 28-10-2003 12:11 ]