Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail client/server sourcecode

Status
Not open for further replies.

ivanius

Programmer
Jun 15, 2005
5
0
0
FR
I'm new in visual c++ programming. Before i programmed with php only.
And now i have to create the client/server mail application using ms visual c++ with the folowing parameters: connection security provided with 'ssleay', file compression is based on '.Z' technologie wich is compatible for both unix and windows. And one more thing, using "curl", are there its implementations for visual c++?
cordialement,
Ivan.
 
so you have to write a client AND a server and not use a standard smtp server?

you might also want to take a look at how to just write a client.. ie how the client should communicate with the server. there is a standard set of commands you can send to the server from teh client to send/ receive email.

 
Ok, maybe you know, is it possible to build mail client based on existing client (Outlook for example)?
 
what do you mean by "based on"?

of course, its possible to build something like it! MS already did it :p

Please be more specific...

if you mean can you add functionality to it, then i think you can do it using vba. but teh server you use must support all that stuff.. like the encryption mechanism you mentioned. i have never heard of it...
 
By saying "based on" i mean the using the outlook's mail address book by my mail programm... and in general, i want to build the ordinary mail client (as outlook) which use 'ssl' for file transfer. to sipmlify my work i thought to use the basic functionalities of the simple mail client and then to expand it with my own code... i hope i was pretty clear :eek:)
 
well.. i dont' really know much about encryption and that sort of stuff.. but i wrote a simple program to send an email. you might be able to use this code as a starting point.. to see how to communicate with an smtp server. there are some issues with it.. like the calls to send and receive. this is some code i found.. i modified it a lot tho (and i odn't have access to my own code at the moment).. but it will give you a good idea.. also.. how familiar are you with winsock? if you are familiar with it, you will see that teh way the code sends and receives over a socket is just awful.. i'm sure you can fix that if you are familiar with it.. otherwise let me know.. i will send you methods to send/receive properly when i have access to my own code.

Code:
if (!socket.Create(0, SOCK_STREAM))
{
AfxMessageBox("Could not create socket!");
res=socket.GetLastError(); 
return;
}

if (!socket.Connect(m_SmtpServer, 25))
{
TRACE(sendbuf);
AfxMessageBox("Could not connect to SMTP Service on server!");
res=socket.GetLastError();
socket.Close ();
return; 
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
// Generate and send lp check request to socket

strcpy(command,"EHLO MY_APPLICATION");
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if ((returnbuf[0]=='2')&&(returnbuf[1]=='5')&&(returnbuf[2]=='0'))
{}
else
{
AfxMessageBox("EHLO command not understood by server!");
socket.Close ();
return;
}
char size[10];
sprintf(size,"%d",strlen(sendbuf));
strcpy(command,"MAIL From:<");
strcat(command,m_SmtpFrom);
strcat(command,"> ");
strcat(command,"SIZE=");
strcat(command,size);
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
memset(returnbuf,0,1024);
if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if ((returnbuf[0]=='2')&&(returnbuf[1]=='5')&&(returnbuf[2]=='0'))
{}
else
{
CString Message;
Message="From Field is invalid! Error Received: \r\n\r\n";
Message+=returnbuf;
AfxMessageBox(Message);
socket.Close ();
return;
}
strcpy(command,"RCPT To:<");
strcat(command,info->mailTo);
strcat(command,"> \r\n");
len=strlen(command);
if (socket.Send (command,len)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if ((returnbuf[0]=='2')&&(returnbuf[1]=='5')&&(returnbuf[2]=='0'))
{}
else
{
AfxMessageBox("Recipient not valid!");
socket.Close ();
return;
}

strcpy(command,"DATA");
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if ((returnbuf[0]=='3')&&(returnbuf[1]=='5')&&(returnbuf[2]=='4'))
{}
else
{
AfxMessageBox("DATA command not understood by server!");
socket.Close ();
return;
}

strcpy(command,sendbuf);
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

strcpy(command,".");
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}
if ((returnbuf[0]=='2')&&(returnbuf[1]=='5')&&(returnbuf[2]=='0'))
{}
else
{
AfxMessageBox("E-Mail not processed by server!");
socket.Close ();
return;
}

strcpy(command,"QUIT");
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError(); 
socket.Close ();
return;
}

socket.Close ();

[code]
 
oh yeah.. as for using the address book.. i think you can. outlook has a specific file extension for an address book and i think its just in csv format.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top