the MAIL command in UNIX and Pipes

This is a discussion on the MAIL command in UNIX and Pipes within the Linux Programming forums, part of the Platform Specific Boards category; twm, I think you're getting confused about who posted....

  1. #16
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    twm, I think you're getting confused about who posted.

  2. #17
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >twm, I think you're getting confused about who posted.
    How so? The first part was to you, the second to RoshanX. As far as I can tell, each comment was sent to the proper person.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #18
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    Nope , won't work. It will work if I use "Mail" instead of "mail". And I am using a sun os.

  4. #19
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    try doing something like:
    Code:
    ...
    pipe_id=popen(mail_command,"w");
    fprintf(pipe_id,"Subject: %s\n",subject); //subject placed here
    for(j=0;j<i;j++)
    {
          fprintf(pipe_id,"%s",list[j]);
    }
    fprintf(pipe_id,"%c",EOF);
    ...
    I'm not sure if you need the newline or if it's best to use it there, but it should work.

  5. #20
    Registered User
    Join Date
    Sep 2002
    Posts
    52

    Sending email thingie

    This is a tad late, but you could always do something like this (to solve the discrepency about "mail" and "Mail" :P)

    Code:
    #define YourEmail "me@mydomain.com"
    FILE *email;
    char cmd[64] = "";
    
    if((email = fopen("mail", "a+")) == NULL)
    	die("Cannot open text file for email.\n");
    
    fprintf(email, "To: %s\n", recpt);
    fprintf(email, "From: %s\n", YourEmail);
    fprintf(email, "Subject: There are %d users using %d processes\n\n", user_count, proc_count);
    
    /*
    ** fprintf(email, "message line here\n");
    ** etc
    */
    
    fclose(email);
    
    sprintf(cmd, "/usr/lib/sendmail %s < mail", recpt);
    system(cmd);
    Not the best way, but it works, and I know, I had to use system()

    I'm sure there are other ways, such as "fastmail", or "sendmail -t with popen() and pclose()", but like I said, this was just an idea I had and decided to post because of the "mail" "Mail" discussion and to show that the code for it isn't that long in C, as the other person suggested.
    - Daniel Wallace

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classical Unix IPC mechanisms
    By cola23 in forum C Programming
    Replies: 1
    Last Post: 02-06-2009, 04:54 AM
  2. Unix pipe simulation
    By TaviO! in forum C Programming
    Replies: 4
    Last Post: 03-19-2008, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21