SMTP client

B

Bill

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:[email protected]. 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
 
J

John Harrison

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:[email protected]. 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
 
B

Bill

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:[email protected]. 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
 
T

Thomas J. Gritzan

Bill said:
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
 
B

Bill

Bill said:
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.
 
B

Bill

Thanks for all the help.

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

Thanks bunches,
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top