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;
}

Recommended Answers

All 5 Replies

Did you not see the C section? It's right below the C++ one.
But it seems that your problem is that you're trying to link a library that does not exist. If you need it for this program, you'll have to install it.

Anuragcoder, do you mind if I ask where you're getting all this source code from?

The problems you're having and the questions you're asking don't seem to match with the level of the code you're pasting.

First with the syntax highlighting, then with the press enter twice, now with this network code. Also, I see before you claim to have written a full cashier interface.

These are simple problems and errors that someone of the calibre that can write (or is expected to write) programs of that nature should not be having an issue with.

The problem is in the winsock library. When you call functions from that library, you get linker error.
Write a simple 2-3 line code calling a function from winsock library to check if your library is installed correctly

Thanks a lot abhimanipal.
and as for ketsuekiame........please...errors are made by even greatest of the great.
i do not have time that's all

and as for enter twice code,
i better suggest using a delimiter.
and as for syntax highlighting....
i better use colorer(or atleast its kernel)

anuragcoder>

and as for ketsuekiame........please...errors are made by even greatest of the great.
i do not have time that's all

However, greatness is measured by the smallest of its details.

And here's a detail explained to you: "Since you don't have time, we do not have time for you"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.