Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C function to interact with /usr/sbin/sendmail

Posted on 2003-02-23
4
Medium Priority
?
603 Views
Last Modified: 2006-11-17
I'm trying to do a function to send emails using Linux's /usr/sbin/sendmail. My code is:

void send_email(const char *email_address)
{
     FILE *email;
     email = popen("/usr/sbin/sendmail -t", "w");
     fprintf(email, "To: %s\n", email_address);
     fprintf(email, "From: %s\n", "user@domain.com\0");
     fprintf(email, "Subject: %s\n", "Automatic email\0");
     fprintf(email, "This is the email body.\n\n");
     fprintf(email, "\n");
     pclose(email);
}

It does not work.
0
Comment
Question by:wguiot
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
skian earned 120 total points
ID: 8008784

This piece of code works here (rh7.2).
Do you use valid "from" and "to" addresses
wrt your sendmail config ?

Stephane

0
 

Author Comment

by:wguiot
ID: 8017078
I'm using valid FROM and TO addresses.

What about "wrt your sendmail config"? I don't understand your comment. Is there something I need to do in the sendmail config?
0
 
LVL 1

Expert Comment

by:skian
ID: 8023928

Well, your current sendmail config may not allow
mail relay, ie it could reject a mail if the TO
or FROM address is not known.
For example, to have this piece of code running
here, I had to replace the from address by mylogin@localhost

What is the return value from pclose ?

Have you tried sending the same message from
the shell command line ?

Stephane
0
 

Author Comment

by:wguiot
ID: 8037937
The function works, the call to it was unreachable.

My bad!.

Thanks, anyway. I'm accepting the answer because it might serve as an example for pipes for someone else.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses

579 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