SMTP error with data command

Jul 6, 2014 at 10:38pm
Hello :)

I work currently on the program and I need send a mail. I have a problem with a data SMTP command. Indeed, this command return this error message:

503 5.5.0 <DATA>: Data command rejected: Improper use of SMTP command pipelining

This is my source code (just the interesting part ;)):

1
2
3
4
5
6
7
8
9
10
char data[] = "HELO smtp.yopmail.com\n"
                  "MAIL FROM:<test@gmail.com>\n"
                  "RCPT TO:<zaegffhgjhgfghjtertfgd@yopmail.com>\n"
                  "DATA\n"
                  "From: <test@gmail.com>\n"
                  "To: <zaegffhgjhgfghjtertfgd@yopmail.com>\n"
                  "Subject: Test\n"
                  "Le corp c'est ici =)\n"
                  ".\n"
                  "QUIT\n";


I don't understand why it don't work because the same command work when I use it manualy in console. :/

If it can help you, I'm on Ubuntu and... I'm here if you need more informations :)

Thank in advance ;)

Jul 7, 2014 at 10:49am
One possible source of this problem could be that you don't wait for an answer of the server when sending another message/command.
Jul 7, 2014 at 11:09am
I try it in this time this solution but I have a another problem VERY strange... Bad syntax error... The code is EXACTLY the same, but when I send it one by one I have this error on the next command:

1
2
char FROM[] = "MAIL FROM:<test@gmail.com>\n";
send(sock, FROM, sizeof(FROM)+2, 0);


return:

500 5.5.2 Error: bad syntax

The HELO smtp... goes well but the rest not work. It's the same error for each instruction when they are send one by one.
I don't understand why it don't work with the same SMTP source code :/

I think my first problem is something like that too. But why "bad syntax error"? It's strange... Or I have don't understand something ^^'
Jul 7, 2014 at 11:20am
Why this sizeof(FROM)+2?
Besides the trailing zero you send two invalid bytes of data. I'd say that even the trailing 0 is a problem.

You may consider to use a library for this. POCO has already this functionality:

http://pocoproject.org/docs/

See Net/Mail
Jul 7, 2014 at 11:50am
+2 It's an error, I was testing a solution but it's not good.
With or without +2 the return it's always the same.

Thank you for the library but, I prefere make a mail sender by myself to really understand how it to work :)

This is my source code without +2 (sorry again):

1
2
char FROM[] = "MAIL FROM:<test@gmail.com>\n";
send(sock, FROM, sizeof(FROM), 0);


And the return is a same, bad syntax.
Last edited on Jul 7, 2014 at 11:51am
Jul 7, 2014 at 11:59am
You're still transmitting the terminating 0. Better use strlen(...) instead of sizeof():

1
2
char FROM[] = "MAIL FROM:<test@gmail.com>\n";
send(sock, FROM, strlen(FROM), 0);


[EDIT]
You might want take a look at code project:

http://www.codeproject.com/Articles/28806/SMTP-Client
Last edited on Jul 7, 2014 at 12:05pm
Jul 7, 2014 at 12:23pm
With sizeof or strlen the return is a same :/ I have also try to write manually the lenght and always this bad syntax error...

I have see your link but my answer isn't here :/
Jul 7, 2014 at 12:33pm
I suggest to take a closer look.

For instance
Each line sent by the client ought to be finished by "\r\n".

You're sending just "\n"

The correct order of request/response is certainly important too.
Jul 7, 2014 at 12:43pm
If I don't say a foolishness, the \r is use to return to the beginning of the line and \n to jump a line on Windows. On linux the \n is sufficient to jump a line and back to his beginning. Therefore, \r is useless on linux. I have still tried with \r and don't work either :/
Jul 7, 2014 at 2:43pm
Do not mix concepts.

The default end of line for windows is "\r\n"
The required end of line for SMTP is "\r\n"

So, if you store text with a text editor under windows it is very likely that all line endings are according to the requirement of SMTP

I don't understand why it don't work because the same command work when I use it manualy in console. :/
This is a strong hint that you have still problems with the line endings. Replace all line endings that currently have only "\n" with "\r\n"
Jul 7, 2014 at 8:47pm
Ok, sorry, I did not know \r\n it's required for SMTP, I thought that \n enough :)

But I have always the same problem ^^'
Jul 9, 2014 at 9:30am
Solve :D

The problem was that I store the mails data in one cell instead allocate one data by cell.

This is my new source code:

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
    char HELO[4][100] = {"HELO smtp.gmail.com\n",
                        "MAIL FROM: <test@yahoo.com>\n",
                        "RCPT TO: <exemple@gmail.com>\n",
                        "DATA\r\n"};

    char DATA[4][100]   {"From: <test@yahoo.com>\n",
                        "To: <exemple@gmail.com>\n",
                        "Subject: Test\n",
                        "Le corp c'est ici =)\n"};

    char QUIT[2][100]   {".\n",
                        "QUIT\n"};

    for(int i = 0; i<4; i++)
    {
        send(sock, HELO[i], strlen(HELO[i]), 0);
        recept_S(sock);
    }

    for(int i = 0; i<4; i++)
        send(sock, DATA[i], strlen(DATA[i]), 0);

    for(int i = 0; i<2; i++)
    {
        send(sock, QUIT[i], strlen(QUIT[i]), 0);
        recept_S(sock);
    }


Thank you very much to your help ^^
Topic archived. No new replies allowed.