From: "Olaf van der Spek" Newsgroups: comp.os.msdos.djgpp References: <_zL75.80726$NF5 DOT 1352833 AT afrodite DOT telenet-ops DOT be> Subject: Re: Pipe to sendmail (like Perl) Lines: 97 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: Date: Mon, 03 Jul 2000 07:39:13 GMT NNTP-Posting-Host: 213.46.21.6 X-Complaints-To: abuse AT chello DOT nl X-Trace: flipper 962609953 213.46.21.6 (Mon, 03 Jul 2000 09:39:13 MET DST) NNTP-Posting-Date: Mon, 03 Jul 2000 09:39:13 MET DST Organization: Chello Broadband To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Tim "Zastai" Van Holder" schreef in bericht news:_zL75.80726$NF5 DOT 1352833 AT afrodite DOT telenet-ops DOT be... > Hi, > > I don't think C++ has pipe-specific functions in its library (ie I don't > think there's a pipestream class), but you can use the C popen()/pclose() > calls to achieve what you want: I tried this: #include int main() { FILE* mail = popen("/usr/sbin/sendmail", "wt"); cout << mail << endl; return 0; } But the output is: (nil) Sendmail does exist: /cgi-bin/cgi_input > ls -l /usr/sbin/sendmail -r-sr-xr-x 1 root root 390424 Nov 9 1999 /usr/sbin/sendmail So what could be the problem? > > ---- > #include > > extern char *to, *from, *subject, *body; > > int > main(void) > { > FILE* mailpipe = popen("/usr/bin/sendmail -oi -t"); > if (mailpipe != 0) { > fprintf (mailpipe, "To: %s\nFrom: %s\nSubject: %s\n", to, from, > subject); > fputs (mailpipe, body); > pclose (mailpipe); > } else cerr << "Couldn't open pipe to mailprogram." << endl; > return 0; > } > ---- > > Zastai > > Olaf van der Spek wrote in message > news:l%K75.252146$k22 DOT 1109779 AT flipper... > > Hi, > > > > I try to use a C++ program to send a mail using sendmail on a Unix server. > > In Perl, you can use this: > > $mailprog = '/usr/sbin/sendmail'; > > open (MAIL, "|$mailprog $in{'address'}") || die "Can't open > > $mailprog!\n"; > > print MAIL "From: $admin_email\n"; > > print MAIL "Subject: You are added!\n\n"; > > print MAIL < > This is to confirm your addition to the $list_name. > > to_the_end > > > > So in C++, I tried: > > void send_mail(const string& from, const string& to, const string& > subject, > > const string& body) > > { > > ofstream mail; > > mail.open("|/usr/sbin/sendmail -oi -t"); > > if (!mail.is_open()) > > cout << "Can't open pipe to sendmail" << endl; > > mail << "To: " << to << endl > > << "From: " << from << endl > > << "Subject: " << subject << endl > > << body; > > } > > > > But that didn't work, I got the error "Can't open pipe to sendmail". > > Anybody knows how this could be solved? > > > > -- > > > > Olaf van der Spek > > Almere, Holland > > Olaf AT XCC DOT TMFWeb DOT NL > > http://xcc.tiberian.com/ > > > > > >