[rescue] Need Mail Program Suggestions

Dave McGuire mcguire at neurotica.com
Sun Feb 3 15:27:35 CST 2002


On February 3, Andrew_Rotramel at cch-lis.com wrote:
> Next week I have to set up an application that involves sending e-mail
> messages to customers. Each message must have an attachment. I read the man
> page and got sendmail configured to send mail to the outside world.
> However, reading the man pages for mail and mailx, I have concluded that
> they don't allow me to include attachments with messages.
> 
> If I am wrong about mail and/or mailx, please set me straight. Or if the
> tasks is completed just with sendmail, please offer advice. If I am correct
> about mail and/or mailx, what mail program can you folks recommend? I have
> EasySpooler 6.1, which has some sort of mail option, but have not looked
> too closely at it yet.

  I can't help you with the attachment stuff.  Besides, remember,
email isn't a file-transfer mechanism. ;)  I would suggest a nice
alternative might be to stick the file on a web server, configured for
local access only if needed, and email a URL.  Pass by reference, not
by value.

  As far as sending the email...you didn't mention what language you're
working in...I work primarily in C, here's an example of a way to send
email from a C program:

 /* ------------------------------------------- */
...

#define SENDMAIL_PATH "/usr/sbin/sendmail"
  pid_t sub_pid;
  int fd[2];
  char header[256], msg[1024];
  FILE *sendmail;


  sprintf(header, "From: <blahblahblah>\nTo: %s\nSubject: %s\n\n"
          recipient_list, subject_str);

  sprintf(msg, "blah blah blah\n");

  if ((sub_pid = fork()) < 0)
    {
      fprintf(stderr, "send_email(): error forking subprocess: %s\n",
              strerror(errno));
      return(0);
    }

  if (sub_pid)                  /* parent process */
    {
      close(fd[0]);             /* close read side */
      write(fd[1], header, strlen(header));
      write(fd[1], msg, strlen(msg));
      close(fd[1]);
      waitpid(sub_pid, &cldstat, 0);
    }
  else                          /* child process */
    {
      close(fd[1]);             /* close write side */

      if (fd[0] != STDIN_FILENO)
        {
          if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO)
            fprintf(stderr, "send_email(): dup2() failed: %s\n",
                    strerror(errno));

          close(fd[0]);
        }

      execl(SENDMAIL_PATH, "sendmail", "-t", "-oi", (char *)NULL);
      _exit(0);
    }

 /* ------------------------------------------- */


    -Dave

-- 
Dave McGuire
St. Petersburg, FL         "Less talk.  More synthohol." --Lt. Worf



More information about the rescue mailing list