Mail Archives: djgpp/2000/07/02/14:16:34
From: | "Tim \"Zastai\" Van Holder" <zastai AT hotmail DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
References: | <l%K75.252146$k22 DOT 1109779 AT flipper>
|
Subject: | Re: Pipe to sendmail (like Perl)
|
Lines: | 70
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300
|
Message-ID: | <_zL75.80726$NF5.1352833@afrodite.telenet-ops.be>
|
Date: | Sun, 02 Jul 2000 18:10:02 GMT
|
NNTP-Posting-Host: | 213.224.63.5
|
X-Trace: | afrodite.telenet-ops.be 962561402 213.224.63.5 (Sun, 02 Jul 2000 20:10:02 MET DST)
|
NNTP-Posting-Date: | Sun, 02 Jul 2000 20:10:02 MET DST
|
Organization: | Pandora - Met vlotte tred op Internet
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
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:
----
#include <cstdio>
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 <Olaf AT XCC DOT TMFWeb DOT NL> 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 <<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 -