ViaThinkSoft CodeLib
Dieser Artikel befindet sich in der Kategorie:
CodeLib → Programmierhilfen → C / C++
#include <stdio.h>
#include <stdbool.h> // bool
#include <sysexits.h> // EX_OK
# define BFR_SIZE 2048
//********************************************************************************************
//
// sendmail
//
// Sendet eine E-Mail
//
// Note: At the paramters "from" and "to" you can use following syntax
// to show a specific name at the user client instead of only the mail address:
// Your Real Name <your@mail_address.com>
static bool sendmail (const char *from, const char *to, const char *subject, const char *mail_text)
{
FILE *fp = popen("/usr/lib/sendmail -t -i", "w");
if (fp) {
char bfr[BFR_SIZE];
snprintf(bfr, BFR_SIZE, "From: %s\r\n", from);
fputs(bfr, fp);
snprintf(bfr, BFR_SIZE, "To: %s\r\n", to);
fputs(bfr, fp);
snprintf(bfr, BFR_SIZE, "Subject: %s\r\n", subject);
fputs(bfr, fp);
fputs("\r\n", fp);
fputs(mail_text, fp);
fputs("\r\n", fp);
fflush(fp);
return (pclose(fp) == EX_OK);
} else {
return false;
}
}
Daniel Marschall
ViaThinkSoft Mitbegründer
ViaThinkSoft Mitbegründer