Re: how can I send the error message to the user by email?
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 9 Apr 2006 11:58:10 -0700
DaVinci wrote:
Bill Pursell wrote:
DaVinci wrote:
how can I send the error message to the user by email?Probably the easiest way would be:
such as
void sendmail(std::string errormsg ,std::string email)
{
}
void
sendmail(char *email_address, char *subject, char *message)
{
char t[BUFSIZ];
snprintf(t, BUFSIZ, "echo \"%s\" | mail -s %s %s",
message, subject, email_address);
system(t);
}
Yes,it works ok.but how it work?
The short answer is:
% man mail
% man system
The long answer is:
Mail reads stdin and sends the contents to the specified
user with the specified subject. System spawns a shell
and sends the contents of the message (via echo) to the
input stream of an invocation of mail. As previously
pointed out in this thread, this is extremely dangerous,
as anyone who can manipulate the message content
can use the system() call to execute arbitrary instructions.
This is probably the reason that popen() was suggested.
However, I think there is an overall better approach. Namely,
this probably shouldn't be done in C++. I have never
had a reason to use system(). Any time it would be
appropriate, it is more appropriate to re-write the application
in a higher level language, like Python. You might consider
having your code dump its error message to a log file, and have
some other process handle the e-mailing of the
error log (for example, the parent of the process
that is having errors). I say this because system() is a
resource hog, and if you are willing to use it then performance
is obviously not an issue in that section of code. If performance
isn't a concern, then use Python.
.
- References:
- how can I send the error message to the user by email?
- From: DaVinci
- Re: how can I send the error message to the user by email?
- From: Bill Pursell
- Re: how can I send the error message to the user by email?
- From: DaVinci
- how can I send the error message to the user by email?
- Prev by Date: Re: how can I send the error message to the user by email?
- Next by Date: Re: Busy wait vs something better
- Previous by thread: Re: how can I send the error message to the user by email?
- Next by thread: Re: how can I send the error message to the user by email?
- Index(es):
Relevant Pages
|
|