473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SMTP client

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
6 5437
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
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
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
>
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Carter | last post by:
I'm trying to create a mail server in Twisted. I either get SMTPSenderRefused or SMTPException: SMTP AUTH extension not supported by server. What do I need to do to get it to work?
21
by: Nancy | last post by:
Hi, Guys, Is there any other way to use python or mod_python writing a web page? I mean, not use "form.py/email", no SMTP server. <form action="form.py/email" method="POST"> ... Thanks a lot. ...
1
by: bivin | last post by:
hai i am requesting your technical support. please help me. i have been working with this for five days. the problem is relating with the smtp. i am trying to send an email from the asp.net...
6
by: John Salerno | last post by:
If I want to write a cgi script that reads the contents of an HTML form and emails it to me, what would I use as the host parameter for my SMTP instance? The example in the docs is 'localhost', but...
2
by: oliu321 | last post by:
Hi, First I am not trying to write a client to talk with hotmail straightly. I am trying to write some codes to send emails through a SMTP server. I wrote a C++ version using pure socket...
5
by: Sin Jeong-hun | last post by:
Hi. I would like to let users send bug reports or other messages to me. Maybe the easiest way to send e-mails from my application is just use the default e-mail agent by executing a link...
1
by: dansuthar | last post by:
Hi everyone there, I want some help in sending mails using .net 2.0 form vb.net. i use the following code to send SMTP Mails: Code:Dim client As New Net.Mail.SmtpClient("smtp.gmail.com") Dim mm...
1
by: Jeff | last post by:
I am receiving the following error: // error: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 No...
1
by: tshad | last post by:
I have a W2K3 Server we are setting up to run a Windows Service for a client at their location. I don't want this machine to go through exchange or their local mail server, I just want the...
4
by: Brian | last post by:
Hello all, we don't actually host our own server but still should work the same. Here is the error message i get "error mailbox unavailable. The server response was: must be authenticated code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.