----------------------------------------------------------------------- Mud Email v1.0 by Xerves (September 16 2002) Xerves is the admin/owner of Rafermand (mud.rafermand.net port 3002) Website: http://www.rafermand.net Contact: xerves@rafermand.net ----------------------------------------------------------------------- I think I did this because 1. I am going to release a player account system soon and this code will be part of it. 2. Eos posted a small snippet about this and I thought I would actually do something similiar. If you are looking for a way to send email to people from within the mud or send email notifications to a list of people, this is a good way to go. It uses the internal mail system in a linux machine and sends out emails. You can either use this in the code by calling the emailing function, or use the do_sendmail function to actually write emails. Enjoy (NOTE: This uses the mail command, type mail -h in linux to see if you have access to this command) ------------- Mud.h ------------- Find struct pc_data In this structure at the end, add this char *sendmail; //buffer used to send an email Find /* timer types ONLY below this point */ SUB_TIMER_DO_ABORT = 128, Before the comment (the /*) add this as the last item SUB_WRITING_EMAIL, Find the following line -- Thanks John #define DEITY_LIST "deity.lst" /* List of deities */ After it add #define EMAIL_FILE SYSTEM_DIR "email.dat" //Email file for sending out email -------------- Comm.c -------------- Find this function void nanny(DESCRIPTOR_DATA * d, char *argument) Before it add these functions char *clean_message(char *str) { static char cleanstring[1000]; int x = 0; strcpy(cleanstring, ""); for (;;) { if (*str == '\0') { cleanstring[x] = *str; return &cleanstring[0]; } if (*str != '\r') { cleanstring[x]= *str; str++; x++; } else str++; } return NULL; } void send_email(char *subject, char *email, char *message, CHAR_DATA *ch) { static char sendstring[1000]; FILE *fp; FILE *mfp; #define MAIL_ROOT_DIR "/bin/mail" strcpy(sendstring, ""); message = clean_message(message); //gets rid of the /r in the message if there are any.. fp = fopen(EMAIL_FILE, "w"); fprintf(fp, "%s", message); fclose(fp); //sprintf(sendstring, "mail -s \"%s\" \"%s\" < %s", subject, email, EMAIL_FILE); //system(&sendstring[0]); sprintf(sendstring, "%s -s \"%s\" \"%s\" < %s", MAIL_ROOT_DIR, subject, email, EMAIL_FILE); if ((mfp = popen( sendstring, "w" )) == NULL) { if (ch) send_to_char("The message was not sent because the mail program could not be found.\n\r", ch); bug("send_email: Could not location mail."); return; } pclose(mfp); remove(EMAIL_FILE); if (ch) ch_printf(ch, "Your email has been sent to %s\n\r", email); } int check_email_syntax(char *arg1, char *arg2) { int x; for (x=0;;x++) { if (arg1[x] == 34 || arg1[x] == 39) // a " and a ' return FALSE; if (arg1[x] == '\0') break; } for (x=0;;x++) { if (arg2[x] == 34 || arg2[x] == 39) // a " and a ' return FALSE; if (arg2[x] == '\0') break; } return TRUE; } void do_sendmail(CHAR_DATA *ch, char *argument) { char arg1[100]; char arg2[100]; static char *passargument; if (ch->dest_buf) { argument = ch->dest_buf; } else { passargument = ""; } passargument = argument; if (IS_NPC(ch)) { send_to_char("Huh?\n\r", ch); return; } if (argument[0] == '\0') { send_to_char("Syntax: sendmail \"\" \"\"\n\r", ch); send_to_char("Once that is typed, you will be sent into the buffer.\n\r", ch); return; } argument = one_argument(argument, arg1); argument = one_argument(argument, arg2); if (arg1[0] == '\0') { send_to_char("You need to supply a subject.\n\r", ch); return; } if (arg2[0] == '\0') { send_to_char("You need to supply an email address.\n\r", ch); return; } if (strlen(arg1) > 95) { send_to_char("Subject cannot be longer than 95 characters.\n\r", ch); return; } if (strlen(arg1) > 95) { send_to_char("recepient's email address cannot be longer than 95 characters.\n\r", ch); return; } if (!check_email_syntax(arg1, arg2)) { send_to_char("You cannot supply any \" or \' in your subject or recepient.\n\r", ch); return; } switch (ch->substate) { default: bug("do_description: illegal substate", 0); return; case SUB_RESTRICTED: send_to_char("You cannot use this command from within another command.\n\r", ch); return; case SUB_NONE: if (ch->pcdata->sendmail) STRFREE(ch->pcdata->sendmail); ch->pcdata->sendmail = STRALLOC(""); ch->substate = SUB_WRITING_EMAIL; ch->dest_buf = passargument; start_editing(ch, ch->pcdata->sendmail); return; case SUB_WRITING_EMAIL: STRFREE(ch->pcdata->sendmail); passargument = ""; ch->pcdata->sendmail = copy_buffer(ch); send_email(&arg1[0], &arg2[0], ch->pcdata->sendmail, ch); bug("-------------%s is sending an email to %s-------------\n\r", ch->name, arg2); stop_editing(ch); return; } } That is it, do a copyover and create the sendmail function cedit sendmail create do_sendmail cedit sendmail level 51 cedit save cmdtable It is recommended that you leave this command at level 51 or so and perhaps bestow it on mortals that might need it. Leaving this to mortals to use can create a lot of abuse because they can freely send out emails whenever they want to whomever they want and your email address will be attached to it! In addition, you will want to check your mail account on which you are running the mud because anything that doesn't "send" will get bounced back to that account. It is probably best to have a seperate email account for the mud than the one you might be using (if you are using it). This can also run on local ports, I get email from xerves@localhost :-) If you have any questions on this snippet, you may contact me, but don't ask me how to setup your email system in linux, that is for your administrator :-) Lastly, here is a little tip. There is a file in linux called .forward. If you put this in your home directory (the initial directory you login to) and put in your normal email address, you can have all email sent to that address send to your normal email address. Then you can filter it and read it or throw it away if you want. --Xerves