?
Solved

C function to interact with /usr/sbin/sendmail

Posted on 2003-02-23
4
Medium Priority
?
596 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
[X]
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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

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