By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,371 Members | 1,488 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,371 IT Pros & Developers. It's quick & easy.

SMTP client

P: n/a
I am trying to write a small SMTP client. You enter the IP address of the
SMTP server & an EM address & it should send a message with the time to &
from the EM addr similar to a telnet SMTP test.

I have verified that I can send a message with telnet. What the PGM does
is connect to the server, HELO, then send the MAIL FROM:em@test.com. then
it just waits. Its like the server does not receive the MAIL FROM:.

The server (Exchange 2K) log file shows the HELO & a QUIT when I hit
<ctrl> c to stop the program.

What am I missing about an MTP connection?

------------------------PGM----
This builds the mail from: line.

//mail from: - Sender.
strcpy (messageToServer, "mail from:");
strcat (messageToServer, *(argv + 2));
strcat (messageToServer, "\r\n");
sendLine (messageToServer, socketFD);

This send the message to the server.

int sendLine (char message[], int socketFD)
{
/*cout << sizeof (message) << "\t"; //sizeof does not work.
bytesSent = send (socketFD, message, 29, 0);
cout << bytesSent <<"\t";
if (bytesSent == -1)
*/if (send (socketFD, message, 29, 0) == -1)
{
perror ("send");
exit (1);
}
else
{
cout << "Message to server was: " << message;
}

return 0;
------------------------END----

Bill
Nov 5 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Bill wrote:

Some comments below, but note that comms programming is not on topic on
this group (nor do I know anything about it).
I am trying to write a small SMTP client. You enter the IP address of the
SMTP server & an EM address & it should send a message with the time to &
from the EM addr similar to a telnet SMTP test.

I have verified that I can send a message with telnet. What the PGM does
is connect to the server, HELO, then send the MAIL FROM:em@test.com. then
it just waits. Its like the server does not receive the MAIL FROM:.

The server (Exchange 2K) log file shows the HELO & a QUIT when I hit
<ctrl> c to stop the program.

What am I missing about an MTP connection?

------------------------PGM----
This builds the mail from: line.

//mail from: - Sender.
strcpy (messageToServer, "mail from:");
strcat (messageToServer, *(argv + 2));
strcat(messageToServer, argv[2]);

is the same thing and easier to understand.
strcat (messageToServer, "\r\n");
sendLine (messageToServer, socketFD);

This send the message to the server.

int sendLine (char message[], int socketFD)
int sendLine(char* message, int socketFD)

is a more honest way of writing this function. You should be aware that
*either* way message is a pointer not an array.
{
/*cout << sizeof (message) << "\t"; //sizeof does not work.
That is because message is a pointer.

cout << strlen(message) << "\t";

is what you want.
bytesSent = send (socketFD, message, 29, 0);
cout << bytesSent <<"\t";
if (bytesSent == -1)
*/if (send (socketFD, message, 29, 0) == -1)
{
perror ("send");
exit (1);
}
else
{
cout << "Message to server was: " << message;
}

return 0;
------------------------END----

Bill


As I said I have no idea about the comms part of your code, but it is
clear that you're a bit muddled about pointers and arrays and the
relationship between them.

john
Nov 5 '05 #2

P: n/a
On Sat, 05 Nov 2005 16:23:20 +0000, John Harrison wrote:
Bill wrote:

Some comments below, but note that comms programming is not on topic on
this group (nor do I know anything about it).
I am trying to write a small SMTP client. You enter the IP address of the
SMTP server & an EM address & it should send a message with the time to &
from the EM addr similar to a telnet SMTP test.

I have verified that I can send a message with telnet. What the PGM does
is connect to the server, HELO, then send the MAIL FROM:em@test.com. then
it just waits. Its like the server does not receive the MAIL FROM:.

The server (Exchange 2K) log file shows the HELO & a QUIT when I hit
<ctrl> c to stop the program.

What am I missing about an MTP connection?

------------------------PGM----
This builds the mail from: line.

//mail from: - Sender.
strcpy (messageToServer, "mail from:");
strcat (messageToServer, *(argv + 2));


strcat(messageToServer, argv[2]);

is the same thing and easier to understand.
strcat (messageToServer, "\r\n");
sendLine (messageToServer, socketFD);

This send the message to the server.

int sendLine (char message[], int socketFD)


int sendLine(char* message, int socketFD)

is a more honest way of writing this function. You should be aware that
*either* way message is a pointer not an array.
{
/*cout << sizeof (message) << "\t"; //sizeof does not work.


That is because message is a pointer.

cout << strlen(message) << "\t";

is what you want.
bytesSent = send (socketFD, message, 29, 0);
cout << bytesSent <<"\t";
if (bytesSent == -1)
*/if (send (socketFD, message, 29, 0) == -1)
{
perror ("send");
exit (1);
}
else
{
cout << "Message to server was: " << message;
}

return 0;
------------------------END----

Bill


As I said I have no idea about the comms part of your code, but it is
clear that you're a bit muddled about pointers and arrays and the
relationship between them.

john


Thanks for the pointer (no pun). Muddled is a good word. There were some
issues with the (argv + 2) & argv[2]). I may have been doing *(argv[2])

What NNTP would you suggest I post this ??? to.

Thanks again
Bill

Nov 5 '05 #3

P: n/a
Bill schrieb:
I am trying to write a small SMTP client. [...] //mail from: - Sender.
strcpy (messageToServer, "mail from:");
strcat (messageToServer, *(argv + 2));
strcat (messageToServer, "\r\n");
sendLine (messageToServer, socketFD);
[...] [...] if (send (socketFD, message, 29, 0) == -1)
{
perror ("send");
exit (1);
}
else
{
cout << "Message to server was: " << message;
}

[...]

Don't hardcode the length of the "message" buffer as 29, it could cut
off the "\r\n", so the server expects more data.

Should be:

if (send(socketFD, message, strlen(message), 0) == -1)
[...]

Better use std::string in C++.

Thomas
Nov 5 '05 #4

P: n/a
>
What NNTP would you suggest I post this ??? to.

Thanks again
Bill


Not sure. Maybe one with winsock or tcp-ip in it's name. I did a search
on google groups for 'send recv' and it turned up plenty of likely
looking groups.

http://groups.google.co.uk/groups?ie...cv&qt_s=Search

john
Nov 5 '05 #5

P: n/a
On Sat, 05 Nov 2005 18:05:18 +0100, Thomas J. Gritzan wrote:
Bill schrieb:
I am trying to write a small SMTP client.

[...]
//mail from: - Sender.
strcpy (messageToServer, "mail from:");
strcat (messageToServer, *(argv + 2));
strcat (messageToServer, "\r\n");
sendLine (messageToServer, socketFD);

[...]
[...] if (send (socketFD, message, 29, 0) == -1)
{
perror ("send");
exit (1);
}
else
{
cout << "Message to server was: " << message;
}

[...]

Don't hardcode the length of the "message" buffer as 29, it could cut
off the "\r\n", so the server expects more data.

Should be:

if (send(socketFD, message, strlen(message), 0) == -1)
[...]

Better use std::string in C++.

Thomas


I hardcoded to lenght because sizeof(message) was not working. That has
been explained to me to use strlen instead.

Thanks for catching my stupid mistake.

I think I have enough info to get over this hurdle & forge ahead to screw
something else up.
Nov 5 '05 #6

P: n/a
Thanks for all the help.

I will correct me stupid mistakes, oversights, & ignorance & see where it
goes from here.

Thanks bunches,
Bill

Nov 5 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.