We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Sending mail from cgi

obg asked
Medium Priority
Last Modified: 2013-12-25
How do I send a mail from a (ANSI C) cgi program? I don't want the user to interfere. The mail should be entirely automatic. Maybe I have to do this through a JavaScript?
Watch Question

A CGI right?  You need only download a perl script to do that.  "Formmail" or something else will do.



Sorry! I have to use ANSI C. If that can't be done, I have to use some JavaScript, or such.

what platform?


I use a unix platform, but I would like the solution to be as portable as possible. I realize that I can use the system("mail") function, but who will be the sender? - Guess I'll have to try...
Ok. This works on Linux, I assume it is standard. If this sample below doesn't work play with it -- it should work fine. Oh, and to use rmail you need to be running sendmail.

Call system("rmail recipient < filename_to_be_sent");

The first line of the file to be sent should read:
From user_who_sent_it

NOTE: No colon...

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

if you use "mail recipient < filename_to_be_sent", the sender will be the http daemon of your web server.

You can also use "mailx -r recipient -s subject < filename_to_be_sent"

"Sendmail" also performs simliar options.


I know the sender will be the http deamon, but I can change the sender, as mikal said, using From... I can still see, however, that the mail comes from the deamon. What is the difference in this aspect between rmail and mailx?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.