/* open sendmail for writing */
FILE *mh = popen("/usr/sbin/sendmail -ti", "w");
/* generate RFC2822 date string; assumes C locale or compatible in use */
char date_string[32];
time_t t = time(NULL);
strftime(date_string, sizeof(date_string), "%a, %d %b %Y %H:%M:%S %z", gmtime(&t));
/* generate basic/required RFC2822 headers;
* note extra newline on last header */
fprintf(mh, "From: noreply@mymud.com\r\n");
fprintf(mh, "To: %s\r\n", user_email);
fprintf(mh, "Date: %s\r\n", date_string);
fprintf(mh, "Subject: [mymud] password retrieval\r\n\r\n");
/* email body; note that the forum is adding [ url ] tag to the line in the middle, sorry */
fprintf(mh, "This mail is being sent to you because you or someone else has requested password\r\n");
fprintf(mh, "retrieval for the account %s. If you requested your password to be reset, please\r\n", user_account);
fprintf(mh, "click on the following link (or copy it into your browser's address bar):\r\n\r\n");
fprintf(mh, " http://mymud.com/resetpassword.cgi?key=%...", reset_key);
fprintf(mh, "If you did not request for your password to be reset, please ignore this email.\r\n\r\n");
fprintf(mh, "Thank you,\r\n");
fprintf(mh, "– My MUD Team\r\n");
/* clean up */
fclose(mh);
That is, a valid email address is required to which an auto-generated
password is sent when creating a new account. The user can change the
account password after login. Resetting a forgotten password would use
the same mechanism.
I assume there are other servers that have done this, and I'm curious as
to the solution used. In the very brief time I spent looking into
generating emails from an applciation, the two best/simplest options seem
to be piping to ssmtp (a very lightweight MTA) or building the equivalent
SMTP capability right into the server. Have I missed any alternatives?