Auto email

Posted on 1997-03-26
Last Modified: 2013-12-25
I’ve successfully written several CGI scripts with VB.  I'm stumped on a problem at the moment and thought I'd drop you a line to see if you had any ideas.  Basically, I want to get a CGI script to send an email.  Here's the routine: The user fills in a webform and hits submit.  This fires up a CGI (written in VB).  I want the CGI to do 3 things: 1. Store the form info in my database (that's no problem, I've got my CGI doing that); 2. Send an email to a third party (this is the part I'm having difficulty with); and, 3. Send the user a confirmation page (this is also no problem).

One tip I received from a newsgroup was that I have to communicate with a server side application called Sendmail.  Is this correct?  A fellow sent me some code written in C, but I haven't been able to fully decipher it.  I don't want to use mailto:, because I want to take the emailing out of the user's hands, so to speak.  Do you have any suggestions?  I need to know how to speak to SENDMAIL  using my CGI.  I need this information either in Visual Basic (preferably) or plain english.  Alternatively, a translation of the C code to VB would be very useful.

 I want my CGI to 'say' to the email application (residing server side naturally), here' s the address, subject, and body, send it.

Here is the C code I was sent:

/* begin e-mail code */

#define SENDMAIL "/usr/lib/sendmail -t"

void sendEmail(void) {
  FILE *mail;

  if ((mail = popen(SENDMAIL,"w")) == NULL) {
    fprintf(stderr,"Error: Can't open sendmail!\n");
  fprintf(mail,"Subject: Mail from WWW\n");
  fprintf(mail,"This is the body of the mail.\n");

/* end e-mail code */
Question by:strangie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 1827839
Edited text of question

Accepted Solution

Fordream earned 130 total points
ID: 1827840
Hello. I haven't programmed CGI in VB. But I think I can help you. I can understand the C code. That is, sending mail by executing SENDMAIL program remapping stdin and stdout as 'mail'. and posting some data to program by writing to the stream. That is, it affects like when you run sendmail and type like this:
Subject: Mail from WWW

This is the body of the mail.
 I don't know about VB function that does like C function 'popen'. But I have another way to do same.
 First, make a text file that will be posted to SENDMAIL program. like quoted text above. At least, "From:", "To:" fields and body of mail may be required.
 And use system call function with command that runs SENDMAIL redirecting stdin as the text file. for example in C code, like this:

 system("/usr/lib/sendmail -t < /tmp/temporary.txt");

 It will be not much different much in VB code, or another language because It uses same shell to process the command.
 Any questions please write a comment here.

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Redirecting an Outlook attachment to a specific folder? 3 68
Perl script to process a .csv file 18 65
Where to download python requests library 6 65
Powershell Split 18 29
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question