Solved

Auto email

Posted on 1997-03-26
2
175 Views
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");
    return;
  }
  fprintf(mail,"To: someone@somewhere.com\n");
  fprintf(mail,"From: wherever@somewhere.com\n");
  fprintf(mail,"Subject: Mail from WWW\n");
  fprintf(mail,"\n");
  fprintf(mail,"This is the body of the mail.\n");
  pclose(mail);
}

/* end e-mail code */
0
Comment
Question by:strangie
2 Comments
 

Author Comment

by:strangie
Comment Utility
Edited text of question
0
 
LVL 1

Accepted Solution

by:
Fordream earned 130 total points
Comment Utility
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:
"
To: someone@somewhere.com
From: wherever@somewhere.com
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.
 Bye!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now