int main() { printf("A C++ class used to send email, such as for servers.\n"); printf("TLS support (such as for Gmail) requires OPEN_SSL_CLIENT_SUPPORT to be defined\nin RakNetDefines.h.\n"); printf("Difficulty: Beginner\n\n"); FileList fileList; EmailSender emailSender; const char *quote = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."; // const char base64Map[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; // char output[1024]; // emailSender.Base64Encoding(quote, strlen(quote), output, base64Map); // printf("%s", output); char mailServer[128], senderUsername[128], receiver[128], password[128]; printf("Tests sending email.\n"); printf("Enter mail server: "); gets(mailServer); if (mailServer[0]==0) strcpy(mailServer, "smtp.gmail.com"); printf("Enter email account username: "******"*****@*****.**"); printf("Enter receiver email address: "); gets(receiver); if (receiver[0]==0) strcpy(receiver, "*****@*****.**"); printf("Enter password needed to send: "); gets(password); if (password[0]==0) strcpy(password, "jenny120"); // http://mail.google.com/support/bin/answer.py?hl=en&answer=13287 unsigned short hostPort; if (strcmp(mailServer,"smtp.gmail.com")==0) hostPort=465; else hostPort=25; fileList.AddFile("quote.txt", "quote.txt", quote, (const unsigned int) strlen(quote), (const unsigned int) strlen(quote), FileListNodeContext(0,0), false); const char *sendResult=emailSender.Send(mailServer, hostPort, senderUsername, receiver, senderUsername, receiver, "Test subject.", "Test attachment body :).\n.\n..\n.\n(Should be .,.,..,.)\r\n.\r\n.\r\n..\r\n.\r\n(Should be .,.,..,.)12345\r\n.\r\n", &fileList, true, password); if (sendResult!=0) printf("Send Failed! %s", sendResult); else printf("Success (probably).\n"); printf("Press enter to quit.\n"); char buff[256]; gets(buff); return 0; }
LONG ProcessException(struct _EXCEPTION_POINTERS *ExceptionInfo) { char appDescriptor[_MAX_PATH]; if ((CrashReporter::controls.actionToTake & AOC_SILENT_MODE) == 0) { sprintf(appDescriptor, "%s has crashed.\nGenerate a report?", CrashReporter::controls.appName); if (::MessageBox( NULL, appDescriptor, "Crash Reporter", MB_YESNO )==IDNO) { return EXCEPTION_CONTINUE_SEARCH; } } char dumpFilepath[_MAX_PATH]; char dumpFilename[_MAX_PATH]; sprintf(appDescriptor, "%s %s - %s %s", CrashReporter::controls.appName, CrashReporter::controls.appVersion, __DATE__, __TIME__); if ((CrashReporter::controls.actionToTake & AOC_EMAIL_WITH_ATTACHMENT) || (CrashReporter::controls.actionToTake & AOC_WRITE_TO_DISK) ) { if (CrashReporter::controls.actionToTake & AOC_WRITE_TO_DISK) { strcpy(dumpFilepath, CrashReporter::controls.pathToMinidump); WriteFileWithDirectories(dumpFilepath,0,0); AddSlash(dumpFilepath); } else { // Write to a temporary directory if the user doesn't want the dump on the harddrive. if (!GetTempPath( _MAX_PATH, dumpFilepath )) dumpFilepath[0]=0; } unsigned i, dumpFilenameLen; strcpy(dumpFilename, appDescriptor); dumpFilenameLen=(unsigned) strlen(appDescriptor); for (i=0; i < dumpFilenameLen; i++) if (dumpFilename[i]==':' || dumpFilename[i]=='/' || dumpFilename[i]=='\\') dumpFilename[i]='.'; // Remove illegal characters from filename strcat(dumpFilepath, dumpFilename); strcat(dumpFilepath, ".dmp"); HANDLE hFile = CreateFile(dumpFilepath,GENERIC_WRITE, FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if (hFile==INVALID_HANDLE_VALUE) return EXCEPTION_CONTINUE_SEARCH; MINIDUMP_EXCEPTION_INFORMATION eInfo; eInfo.ThreadId = GetCurrentThreadId(); eInfo.ExceptionPointers = ExceptionInfo; eInfo.ClientPointers = FALSE; if (MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, (MINIDUMP_TYPE)CrashReporter::controls.minidumpType, ExceptionInfo ? &eInfo : NULL, NULL, NULL)==false) return EXCEPTION_CONTINUE_SEARCH; CloseHandle(hFile); } char silentModeEmailBody[1024]; char subject[1204]; if (CrashReporter::controls.actionToTake & AOC_EMAIL_NO_ATTACHMENT) { strcpy(subject, CrashReporter::controls.emailSubjectPrefix); strcat(subject, appDescriptor); if (CrashReporter::controls.actionToTake & AOC_SILENT_MODE) { sprintf(silentModeEmailBody, "%s%s version %s has crashed.\r\nIt was compiled on %s %s.\r\n", CrashReporter::controls.emailBody, CrashReporter::controls.appName,CrashReporter::controls.appVersion, __DATE__, __TIME__); if (CrashReporter::controls.actionToTake & AOC_WRITE_TO_DISK) sprintf(silentModeEmailBody+strlen(silentModeEmailBody), "Minidump written to %s \r\n", dumpFilepath); // Silently send email with attachment EmailSender emailSender; emailSender.Send(CrashReporter::controls.SMTPServer, 25, CrashReporter::controls.SMTPAccountName, CrashReporter::controls.emailRecipient, CrashReporter::controls.emailSender, CrashReporter::controls.emailRecipient, subject, silentModeEmailBody, 0, false, CrashReporter::controls.emailPassword); } else { CSendFileTo sendFile; sendFile.SendMail(0, 0, 0, subject, CrashReporter::controls.emailBody, CrashReporter::controls.emailRecipient); } } else if (CrashReporter::controls.actionToTake & AOC_EMAIL_WITH_ATTACHMENT) { strcpy(subject, CrashReporter::controls.emailSubjectPrefix); strcat(subject, dumpFilename); strcat(dumpFilename, ".dmp"); if (CrashReporter::controls.actionToTake & AOC_SILENT_MODE) { sprintf(silentModeEmailBody, "%s%s version %s has crashed.\r\nIt was compiled on %s %s.\r\n", CrashReporter::controls.emailBody, CrashReporter::controls.appName,CrashReporter::controls.appVersion, __DATE__, __TIME__); if (CrashReporter::controls.actionToTake & AOC_WRITE_TO_DISK) sprintf(silentModeEmailBody+strlen(silentModeEmailBody), "Minidump written to %s \r\n", dumpFilepath); // Silently send email with attachment EmailSender emailSender; FileList files; files.AddFile(dumpFilepath,dumpFilename,FileListNodeContext(0,0,0,0)); emailSender.Send(CrashReporter::controls.SMTPServer, 25, CrashReporter::controls.SMTPAccountName, CrashReporter::controls.emailRecipient, CrashReporter::controls.emailSender, CrashReporter::controls.emailRecipient, subject, silentModeEmailBody, &files, false, CrashReporter::controls.emailPassword); } else { CSendFileTo sendFile; sendFile.SendMail(0, dumpFilepath, dumpFilename, subject, CrashReporter::controls.emailBody, CrashReporter::controls.emailRecipient); } } return EXCEPTION_EXECUTE_HANDLER; }