Problem doing an e-mail program in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tyler_durden

    #1

    Problem doing an e-mail program in C

    hi there peeps...
    like I say in the topic, I need to do an e-mail program in C language, and
    has to be made until the 3th of january..the problem is I'm having some
    problems with it.
    I was wondering if someone had a program like this..it has to send
    e-mails, read e-mails from a .txt file and show them in the screen with
    the subject, date, etc...
    can someone please help me out?
    thanks

  • Joona I Palaste

    #2
    Re: Problem doing an e-mail program in C

    tyler_durden <tom4_h4wk@hotm ail.com> scribbled the following:[color=blue]
    > hi there peeps...
    > like I say in the topic, I need to do an e-mail program in C language, and
    > has to be made until the 3th of january..the problem is I'm having some
    > problems with it.
    > I was wondering if someone had a program like this..it has to send
    > e-mails, read e-mails from a .txt file and show them in the screen with
    > the subject, date, etc...
    > can someone please help me out?
    > thanks[/color]

    Sending or reading e-mails is not possible in ISO standard C. Please ask
    in a newsgroup dedicated to your own implementation.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "All that flower power is no match for my glower power!"
    - Montgomery Burns

    Comment

    • Flash Gordon

      #3
      Re: Problem doing an e-mail program in C

      On Tue, 28 Dec 2004 17:06:22 -0500
      "tyler_durd en" <tom4_h4wk@hotm ail.com> wrote:
      [color=blue]
      > hi there peeps...
      > like I say in the topic, I need to do an e-mail program in C language,
      > and has to be made until the 3th of january..the problem is I'm having
      > some problems with it.
      > I was wondering if someone had a program like this..it has to send
      > e-mails, read e-mails from a .txt file and show them in the screen
      > with the subject, date, etc...
      > can someone please help me out?
      > thanks[/color]

      Yes, lots of people could help you. For 50UKP I'll send you the source
      for a program that does all this and more. I'll even give you the
      following advice for free.

      1) All the network stuff is beyond the scope of the C language and hence
      off topic here.

      2) Any sophisticated screen handling you might want is beyond the scope
      of the C standard and hence off topic here.

      3) Around here we tend to help people fix on-topic code that they post,
      not write it for people.

      4) You will certainly need advice from people who know the OS you are
      programing for, so you will have questions that should be asked on an OS
      specific group.

      So I suggest you try to start on the program and find groups where
      specific questions are topical. To do the latter you will have to read
      the FAQ and a weeks worth of posts for any group you think might be
      appropriate before posting.
      --
      Flash Gordon
      Living in interesting times.
      Although my email address says spam, it is real and I read it.

      Comment

      • Keith Thompson

        #4
        Re: Problem doing an e-mail program in C

        "tyler_durd en" <tom4_h4wk@hotm ail.com> writes:[color=blue]
        > hi there peeps...
        > like I say in the topic, I need to do an e-mail program in C language, and
        > has to be made until the 3th of january..the problem is I'm having some
        > problems with it.
        > I was wondering if someone had a program like this..it has to send
        > e-mails, read e-mails from a .txt file and show them in the screen with
        > the subject, date, etc...[/color]

        The January 3 deadline makes me suspect this is a homework assignment.
        There are enough existing e-mail programs floating around that I don't
        believe someone would ask you do to this as part of a paying job; if
        it's a hobby there shouldn't be a deadline. (I'm assuming that's what
        "has to be made until the 3th of january" means; I hope you're taking
        classes in English as well as in C.)

        If this is homework, just send us your instructor's e-mail address,
        and we'll consider writing the program and sending it directly. (You
        wouldn't expect us to do your work for you and not get any credit for
        it, would you?)

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
        We must do something. This is something. Therefore, we must do this.

        Comment

        • infobahn

          #5
          Re: Problem doing an e-mail program in C

          tyler_durden wrote:[color=blue]
          > hi there peeps...
          > like I say in the topic, I need to do an e-mail program in C language, and
          > has to be made until the 3th of january..the problem is I'm having some
          > problems with it.[/color]

          Ah, so the problem is that you're having problems. Okay. What problems
          might they be?
          [color=blue]
          > I was wondering if someone had a program like this..it has to send
          > e-mails, read e-mails from a .txt file and show them in the screen with
          > the subject, date, etc...[/color]

          Many of us have email clients, yes. Some of us even have the C source
          for email clients. But I hope none of us think it would be a good idea
          to send you such source code simply to help you fake your way through
          an assignment.
          [color=blue]
          > can someone please help me out?[/color]

          Sure. The whole of your program, with the exception of the sockets bit
          (and it's not clear from your article whether you're supposed to do a
          "real" email client or something that merely imitates one using files),
          can be written in ISO C if you're clever.

          So write it in ISO C, and then let us know if you have problems.

          If you decide to go for flashy
          stuff like graphics, then you'd have to ask about problems with the
          flashy stuff in a newsgroup where flashy stuff is topical, such as
          comp.os.ms-windows.program mer.win32.


          Comment

          • tyler_durden

            #6
            Re: Problem doing an e-mail program in C

            thanks a lot for all your replyes.
            the program is simplier than that, because it doesn't need to actyually
            send the e-mails..
            I have the sheet with the specifications it has to have, but it's in
            portuguese....
            I've already made some of it, the help menu, and the command that asks you
            for the adress, the subject and the message..
            then when you want to exit the program if you press "x" it exits without
            changing anything, but with "q" it has to keep all of the sent messages in
            a file with a certain structure...
            and it has to be able to present the mails in the file by pressing
            "h"...it shows each mail, and its subsject,date and adress..then you can
            delete the mails, os view them...
            Yes, its a homework assignment.
            all the help you can give me is appreciated, and if you think it will help
            I could put my work done till now online, for you to view it...
            thanks a lot...

            Comment

            • tyler_durden

              #7
              Re: Problem doing an e-mail program in C

              If you could at least send me a source code for a simple e-mail program it
              would be great....just to get some ideas of it..

              Comment

              • Mark McIntyre

                #8
                Re: Problem doing an e-mail program in C

                On Wed, 29 Dec 2004 07:42:40 -0500, in comp.lang.c , "tyler_durd en"
                <tom4_h4wk@hotm ail.com> wrote:
                [color=blue]
                >If you could at least send me a source code for a simple e-mail program it
                >would be great....just to get some ideas of it..[/color]

                This is offtopic. I suggest you go look in the gnu archives, or at
                sourceforge. The implementation of blat might be interesting.


                --
                Mark McIntyre
                CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

                Comment

                • Robert B. Clark

                  #9
                  Re: Problem doing an e-mail program in C

                  On Tue, 28 Dec 2004 17:06:22 -0500, "tyler_durd en"
                  <tom4_h4wk@hotm ail.com> wrote:
                  [color=blue]
                  >hi there peeps...
                  >like I say in the topic, I need to do an e-mail program in C language, and
                  >has to be made until the 3th of january..the problem is I'm having some
                  >problems with it.[/color]

                  Dude, you really need to get started on your assignments earlier. I'm
                  sure your instructor didn't assign this problem just today?

                  What are the problems you're having with your code? Procrastination
                  aside, I mean. Post relevant sections of your code and indicate where
                  you're having difficulty.


                  --
                  Robert B. Clark (email ROT13'ed)
                  Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/

                  Comment

                  • Novitas

                    #10
                    Re: Problem doing an e-mail program in C

                    It sounds like you are having problems with specific things (handling
                    file storage and retrieval maybe? Something else?) but you have not
                    identified the specific things you are having issues with.

                    It would be more helpful to start from there and identify those
                    specific issues to the group.

                    Comment

                    • tyler_durden

                      #11
                      Specific problem...now you can help =)

                      I made this command but it gives me a "segmentati on fault" error...can you
                      help me?

                      -------------------------

                      #include <stdio.h>

                      typedef struct mail
                      {
                      char from[120];
                      char to[120];
                      char sub[120];
                      char msg[120];
                      } MAIL;

                      void comandom(MAIL *ptr)
                      {
                      printf("From: \n"); gets(ptr->from);
                      printf("To: \n"); gets(ptr->to);
                      printf("Subject :\n"); gets(ptr->sub);
                      printf("Message :\n"); gets(ptr->msg);


                      }

                      ---------------------------

                      and I need to implement the time and date when I write each e-mail..I have
                      the function which is:
                      -------------------
                      #include<stdio. h>
                      #include<time.h >
                      #define MAX 120

                      void tempo(char *tempo){

                      time_t horact;

                      time(horact);

                      ctime_r(horact, tempo);
                      }


                      -----------------------------

                      but I dunno how to use it..
                      thanks a lot!

                      Comment

                      • tyler_durden

                        #12
                        What I have until now

                        ok..so what I did until now is this...
                        the main file is this one:
                        ------------------------------(progmail.c)----
                        #include <stdio.h> /* para funcoes como printf, scanf, etc */
                        #include <stdlib.h> /* para a funcao exit */
                        #include <string.h> /* para funcoes relacionadas com strings */
                        #define DIMMAIN 20

                        void comandom(void);
                        void comandoC(void);
                        void comandoL(void);

                        int help(){

                        printf ("Help \n \n");
                        printf ("Mail Commands \n \n");


                        printf("------------------------------------------------------------------------\n");
                        printf("| t <message list> type messages
                        |\n");
                        printf("| d <message list> delete messages
                        |\n");
                        printf("| R <message list> reply to message senders
                        |\n");
                        printf("| r <message list> reply to message senders and all
                        recipients |\n");
                        printf("| m <user list> mail to specific users
                        |\n");
                        printf("| q quit, saving unresolved messages in mbox
                        |\n");
                        printf("| x quit, do not remove system mailbox
                        |\n");
                        printf("| h print out active message headers
                        |\n");

                        printf("------------------------------------------------------------------------\n");

                        return 0;

                        }



                        int main (){
                        char c;

                        fopen("mail.txt ","r");

                        printf("E-mail program.\n");


                        do{
                        putchar ('&');
                        scanf("%s",&c);


                        switch (c)
                        {
                        case '?':help();brea k;
                        case 't':printf("ok\ n");break;
                        case 'd':printf("ok\ n");break;
                        case 'R':printf("ok\ n");break;
                        case 'r':printf("ok\ n");break;
                        case 'm':comandom(); break;
                        case 'q':printf("ok\ n");break;
                        case 'x':printf("Pro gram shutting down!\n"); break;
                        case 'h':printf("ok\ n");break;
                        case 'C':comandoC(); break;
                        case 'L':comandoL(); break;
                        default: printf("Unknown command!\n");br eak;
                        }

                        }while (c!='x');

                        return 0;
                        }
                        ---------------------------------

                        my "m" command, which is supposed to ask you for the email informations is
                        this one:
                        ----------------/comandom.c-----------
                        #include <stdio.h>

                        typedef struct mail
                        {
                        char from[120];
                        char to[120];
                        char sub[120];
                        char msg[120];
                        } MAIL;

                        void comandom(MAIL *ptr)
                        {
                        printf("From: \n"); gets(ptr->from);
                        printf("To: \n"); gets(ptr->to);
                        printf("Subject :\n"); gets(ptr->sub);
                        printf("Message :\n"); gets(ptr->msg);


                        }
                        ------------------------------

                        then I have the command "q" which when pressed has to keep all the written
                        emails in a mail.txt fuile..I made this:
                        --------------(comandoq.c)------------
                        #include <stdio.h>

                        FILE *fp;

                        fp = fopen("mail.txt ","a");

                        fprintf(fp,"Fro m:%s\n",from);
                        fprintf(fp,"To: %s\n",to);
                        fprintf(fp,"Sub ject:%s\n",sub) ;
                        fprintf(fp,"Mes sage:%s\n",msg) ;
                        fprintf(fp,"\n" );

                        fclose(fp);

                        }
                        ----------------
                        it's not complete so I woudl like you to help me, please.
                        the output of the mail.txt file has to be something like this:
                        From: trytry@sdgds.co m
                        to: ddsdfsdsf@dfsd. pt
                        Date: ....
                        Subject: hfdhrt
                        Message: fdhdh

                        From: trytry@sdgds.co m
                        to: ddsdfsdsf@dfsd. pt
                        Date: ....
                        Subject: hfdhrt
                        Message: fdhdh

                        From: trytry@sdgds.co m
                        to: ddsdfsdsf@dfsd. pt
                        Date: ....
                        Subject: hfdhrt
                        Message: fdhdh

                        --------------

                        kan you help me please?
                        next I have to do a command that shows in the program the to,date and
                        subject of each message in "mail.txt" like this:

                        & h
                        N 1 <endereço da mensagem1> <data1> <titulo da mensagem1>
                        N 2 <endereço da mensagem2> <data2> <titulo da mensagem2>
                        N 3 <endereço da mensagem3> <data3> <titulo da mensagem3>

                        ...
                        thanks a lot, help me please, it's a case of life or death =)


                        Comment

                        • Flash Gordon

                          #13
                          Re: Specific problem...now you can help =)

                          On Wed, 29 Dec 2004 15:25:59 -0500
                          "tyler_durd en" <tom4_h4wk@hotm ail.com> wrote:
                          [color=blue]
                          > I made this command but it gives me a "segmentati on fault" error...can
                          > you help me?
                          >
                          > -------------------------
                          >
                          > #include <stdio.h>
                          >
                          > typedef struct mail
                          > {
                          > char from[120];
                          > char to[120];
                          > char sub[120];
                          > char msg[120];
                          > } MAIL;
                          >
                          > void comandom(MAIL *ptr)
                          > {
                          > printf("From: \n"); gets(ptr->from);[/color]

                          Using gets is a *very* bad idea. You cannot prevent a user causing a
                          buffer overflow by entering a string too long to enter in to the buffer.
                          Use fgets, but look at what it does first especially in terms of new
                          line and lines longer than the buffer.
                          [color=blue]
                          > printf("To: \n"); gets(ptr->to);
                          > printf("Subject :\n"); gets(ptr->sub);
                          > printf("Message :\n"); gets(ptr->msg);
                          >
                          >
                          > }
                          >
                          > ---------------------------
                          >
                          > and I need to implement the time and date when I write each e-mail..I
                          > have the function which is:
                          > -------------------
                          > #include<stdio. h>
                          > #include<time.h >
                          > #define MAX 120
                          >
                          > void tempo(char *tempo){
                          >
                          > time_t horact;
                          >
                          > time(horact);[/color]

                          The compiler should have complained about this.
                          time(&horact);
                          [color=blue]
                          > ctime_r(horact, tempo);[/color]

                          This is not a standard C function so we don't know about it here.
                          <OT>
                          However, the compiler should have complained about this as well
                          </OT>
                          [color=blue]
                          > }
                          >
                          >
                          > -----------------------------
                          >
                          > but I dunno how to use it..
                          > thanks a lot![/color]

                          You have the source for a function but don't know how to use it? Well,
                          in this case you pass a pointer to a buffer large enough for the longest
                          possible string representation of the time.
                          --
                          Flash Gordon
                          Living in interesting times.
                          Although my email address says spam, it is real and I read it.

                          Comment

                          • tyler_durden

                            #14
                            Re: Specific problem...now you can help =)

                            So I should not use gets?
                            but I need the user to insert the from,to,subject and message...the
                            function of fgets is to get something from a file,right?
                            I thought of using scanf, but then if a space was inserted, it would not
                            keep the information correctly...
                            in the "What I have until now" is all my program until this phase...
                            thanks a lot for your help..


                            Comment

                            • Flash Gordon

                              #15
                              Re: What I have until now

                              On Wed, 29 Dec 2004 16:36:41 -0500
                              "tyler_durd en" <tom4_h4wk@hotm ail.com> wrote:
                              [color=blue]
                              > ok..so what I did until now is this...
                              > the main file is this one:
                              > ------------------------------(progmail.c)----
                              > #include <stdio.h> /* para funcoes como printf, scanf, etc */
                              > #include <stdlib.h> /* para a funcao exit */
                              > #include <string.h> /* para funcoes relacionadas com strings */
                              > #define DIMMAIN 20
                              >
                              > void comandom(void);
                              > void comandoC(void);
                              > void comandoL(void);
                              >
                              > int help(){
                              >
                              > printf ("Help \n \n");
                              > printf ("Mail Commands \n \n");
                              >
                              >
                              > printf("-------------------------------------------------------------
                              > -----------\n");
                              > printf("| t <message list> type messages
                              >
                              > |\n");
                              > printf("| d <message list> delete messages
                              >
                              > |\n");
                              > printf("| R <message list> reply to message senders
                              >
                              > |\n");
                              > printf("| r <message list> reply to message senders and all
                              > recipients |\n");
                              > printf("| m <user list> mail to specific users
                              >
                              > |\n");
                              > printf("| q quit, saving unresolved messages in mbox
                              >
                              > |\n");
                              > printf("| x quit, do not remove system mailbox
                              >
                              > |\n");
                              > printf("| h print out active message headers
                              >
                              > |\n");
                              >
                              > printf("-------------------------------------------------------------
                              > -----------\n");
                              >
                              > return 0;
                              >
                              > }
                              >
                              >
                              >
                              > int main (){
                              > char c;
                              >
                              > fopen("mail.txt ","r");
                              >
                              > printf("E-mail program.\n");
                              >
                              >
                              > do{
                              > putchar ('&');
                              > scanf("%s",&c);[/color]

                              BANG!

                              %s means read a string, which is 0 or more characters followed by a
                              '\0'. So if there are any characters input then a minimum of 2 bytes
                              will be written to c which is only large enough for 1 byte.
                              [color=blue]
                              > switch (c)
                              > {
                              > case '?':help();brea k;
                              > case 't':printf("ok\ n");break;
                              > case 'd':printf("ok\ n");break;
                              > case 'R':printf("ok\ n");break;
                              > case 'r':printf("ok\ n");break;
                              > case 'm':comandom(); break;
                              > case 'q':printf("ok\ n");break;
                              > case 'x':printf("Pro gram shutting down!\n"); break;
                              > case 'h':printf("ok\ n");break;
                              > case 'C':comandoC(); break;
                              > case 'L':comandoL(); break;
                              > default: printf("Unknown command!\n");br eak;
                              > }
                              >
                              > }while (c!='x');
                              >
                              > return 0;
                              > }
                              > ---------------------------------
                              >
                              > my "m" command, which is supposed to ask you for the email
                              > informations is this one:
                              > ----------------/comandom.c-----------
                              > #include <stdio.h>
                              >
                              > typedef struct mail
                              > {
                              > char from[120];
                              > char to[120];
                              > char sub[120];
                              > char msg[120];
                              > } MAIL;
                              >
                              > void comandom(MAIL *ptr)[/color]

                              You called this without any parameters. Always make sure functions are
                              prototyped before they are called.
                              [color=blue]
                              > {
                              > printf("From: \n"); gets(ptr->from);[/color]

                              Still using gets, so once again BANG!
                              [color=blue]
                              > printf("To: \n"); gets(ptr->to);
                              > printf("Subject :\n"); gets(ptr->sub);
                              > printf("Message :\n"); gets(ptr->msg);
                              >
                              >
                              > }
                              > ------------------------------
                              >
                              > then I have the command "q" which when pressed has to keep all the
                              > written emails in a mail.txt fuile..I made this:
                              > --------------(comandoq.c)------------
                              > #include <stdio.h>
                              >
                              > FILE *fp;
                              >
                              > fp = fopen("mail.txt ","a");
                              >
                              > fprintf(fp,"Fro m:%s\n",from);
                              > fprintf(fp,"To: %s\n",to);
                              > fprintf(fp,"Sub ject:%s\n",sub) ;
                              > fprintf(fp,"Mes sage:%s\n",msg) ;
                              > fprintf(fp,"\n" );
                              >
                              > fclose(fp);
                              >
                              > }
                              > ----------------
                              > it's not complete so I woudl like you to help me, please.
                              > the output of the mail.txt file has to be something like this:
                              > From: trytry@sdgds.co m
                              > to: ddsdfsdsf@dfsd. pt
                              > Date: ....
                              > Subject: hfdhrt
                              > Message: fdhdh
                              >
                              > From: trytry@sdgds.co m
                              > to: ddsdfsdsf@dfsd. pt
                              > Date: ....
                              > Subject: hfdhrt
                              > Message: fdhdh
                              >
                              > From: trytry@sdgds.co m
                              > to: ddsdfsdsf@dfsd. pt
                              > Date: ....
                              > Subject: hfdhrt
                              > Message: fdhdh
                              >
                              > --------------
                              >
                              > kan you help me please?
                              > next I have to do a command that shows in the program the to,date and
                              > subject of each message in "mail.txt" like this:
                              >
                              > & h
                              > N 1 <endereço da mensagem1> <data1> <titulo da mensagem1>
                              > N 2 <endereço da mensagem2> <data2> <titulo da mensagem2>
                              > N 3 <endereço da mensagem3> <data3> <titulo da mensagem3>
                              >
                              > ..
                              > thanks a lot, help me please, it's a case of life or death =)
                              >
                              > [/color]


                              --
                              Flash Gordon
                              Living in interesting times.
                              Although my email address says spam, it is real and I read it.

                              Comment

                              Working...