Hey guys,
recently i've tried to compile this command line email program
I get the error:
cannot find -lobjc
ld returned 1 exit status
Here's my code.
Any Help Appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#define NETWORK_ERROR -1
#define NETWORK_OK 0
FILE *fp;
char buffer[200000];
char buff[100];
char mess[200000];
char inserpde[100];
char mage[100];
char sndto[100];
char mesfrm[100];
char temp[200];
char tempone[200];
char *p;
char* TmpStr(size_t);
char* mid (char*,int,int);
void ReportError(int, const char *);
char sendmail( char *filename, char *server, char *to, char *from);
int main(int argc, char *argv[])
{
if (argc!=5 )
{
printf ("\n");
printf("Usage: Filename SmtpServer To From\n");
printf("where:\n");
printf(" FileName = text file containing the messsage\n");
printf(" SmtpServer = server name e.g. smtp.domain.com\n");
printf(" To = recipient's address e.g. myfriend@domain.com\n");
printf(" From = sender's address e.g. me@domain.com\n");
}
else
if(argc==5)
{
if((fp = fopen(argv[1], "r"))==NULL)
{
printf("\nCannot find %s", argv[1]);
printf("\n\nPlease enter the full path for the file\n");
}
else
if((fp = fopen(argv[1],"r"))!=NULL)
{
while (!feof(fp))
{
strcpy(buff,"");
fgets(buff, sizeof(buff), fp);
p = strchr(buff, '\n');
if(p){
*p = '\0';
strcat(buff,"\r\n");
}
strcat(mess,buff);
}
fclose(fp);
strcat(mess,"\r\n.\r\n");
strcpy(mage,argv[1]);
strcpy(inserpde,argv[2]);
strcpy(sndto,argv[3]);
strcpy(mesfrm,argv[4]);
sendmail(mage, inserpde, sndto, mesfrm);
}
}
return 0;
}
char sendmail( char *filename, char *server, char *to, char *from)
{
strcpy(temp,"Message sent");
WORD sockVersion;
WSADATA wsaData;
int nret;
sockVersion = MAKEWORD(1, 1);
WSAStartup(sockVersion, &wsaData);
LPHOSTENT hostEntry;
hostEntry = gethostbyname(inserpde); // This is the host’s name
if (!hostEntry)
{
printf( "Error obtaining host\n");
return -1;
WSACleanup();
}
SOCKET theSocket;
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET)
{
printf("Invalid socket\n");
return -1;
WSACleanup();
}
SOCKADDR_IN serverInfo;
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(25);
nret = connect(theSocket,
(LPSOCKADDR)&serverInfo,
sizeof(struct sockaddr));
if (nret == SOCKET_ERROR)
{
printf("Error connecting to server\n");
return -1;
WSACleanup();
return NETWORK_ERROR;
}
printf("\n");
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
strcpy(buffer, "HELO ");
strcat(buffer,inserpde);
strcat(buffer,"\r\n");
send(theSocket, buffer, strlen(buffer), 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
recv(theSocket, buffer,512, 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
strcpy(buffer, "MAIL FROM: <");
strcat(buffer,mesfrm);
strcat(buffer,">\r\n");
send(theSocket, buffer, strlen(buffer), 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
// printf("%s\n",buffer);
ZeroMemory(buffer, 512);
strcpy(buffer, "RCPT TO: <");
strcat(buffer,sndto);
strcat(buffer,">\r\n");
send(theSocket, buffer, strlen(buffer), 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
strcpy(buffer, "DATA\r\n");
send(theSocket, buffer, strlen(buffer), 0);
//printf("%s\n",buffer);
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
// printf("%s\n",buffer);
ZeroMemory(buffer, 512);
send(theSocket, mess, strlen(mess), 0);
//printf("%s\n",mess);
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
printf("%s\n",buffer);
ZeroMemory(buffer, 512);
strcpy(buffer, "QUIT\r\n");
send(theSocket, buffer, strlen(buffer), 0);
//printf("%s\n",temp);
ZeroMemory(buffer, 512);
recv(theSocket, buffer, 512, 0);
//printf("%s\n",buffer);
closesocket(theSocket);
WSACleanup();
return 0;
}
char *TmpStr (size_t Bites)
{
static int StrCnt;
static char *StrFunc [64];
StrCnt = (StrCnt + 1) & 63;
free (StrFunc[StrCnt]);
return StrFunc[StrCnt] = (char*)calloc(Bites + 256, 1);
}
char *mid (char *S, int start, int length)
{
int tmplen;
char *strtmp;
tmplen = strlen(S);
if(length == -1)
{
length = tmplen - start + 1;
}
strtmp = TmpStr(length);
if(start>tmplen)
{
strtmp[0] = 0;
}
else
{
strncpy(strtmp,&S[start-1],length);
}
strtmp[length] = 0;
return strtmp;
}