delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/02/13:46:53

From: "Olaf van der Spek" <Olaf AT XCC DOT TMFWeb DOT NL>
Newsgroups: comp.os.msdos.djgpp
Subject: Pipe to sendmail (like Perl)
Lines: 38
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: <l%K75.252146$k22.1109779@flipper>
Date: Sun, 02 Jul 2000 17:30:57 GMT
NNTP-Posting-Host: 213.46.21.6
X-Complaints-To: abuse AT chello DOT nl
X-Trace: flipper 962559057 213.46.21.6 (Sun, 02 Jul 2000 19:30:57 MET DST)
NNTP-Posting-Date: Sun, 02 Jul 2000 19:30:57 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

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 <<to_the_end;
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/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019