main.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "EmailSender.h"
  11. #include "FileList.h"
  12. #include <stdio.h>
  13. #include "Gets.h"
  14. int main()
  15. {
  16. printf("A C++ class used to send email, such as for servers.\n");
  17. printf("TLS support (such as for Gmail) requires OPEN_SSL_CLIENT_SUPPORT to be defined\nin RakNetDefines.h.\n");
  18. printf("Difficulty: Beginner\n\n");
  19. RakNet::FileList fileList;
  20. RakNet::EmailSender emailSender;
  21. 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.";
  22. // const char base64Map[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  23. // char output[1024];
  24. // emailSender.Base64Encoding(quote, strlen(quote), output, base64Map);
  25. // printf("%s", output);
  26. char mailServer[128], senderUsername[128], receiver[128], password[128];
  27. printf("Tests sending email.\n");
  28. printf("Enter mail server: ");
  29. Gets(mailServer,sizeof(mailServer));
  30. if (mailServer[0]==0)
  31. strcpy(mailServer, "smtp.gmail.com");
  32. printf("Enter email account username: ");
  33. Gets(senderUsername,sizeof(senderUsername));
  34. if (senderUsername[0]==0)
  35. strcpy(senderUsername, "subspacegod@gmail.com");
  36. printf("Enter receiver email address: ");
  37. Gets(receiver,sizeof(receiver));
  38. if (receiver[0]==0)
  39. strcpy(receiver, "rakkar@rakkar.org");
  40. printf("Enter password needed to send: ");
  41. Gets(password,sizeof(password));
  42. // http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
  43. unsigned short hostPort;
  44. if (strcmp(mailServer,"smtp.gmail.com")==0)
  45. hostPort=465;
  46. else
  47. hostPort=25;
  48. fileList.AddFile("quote.txt", "quote.txt", quote, (const unsigned int) strlen(quote), (const unsigned int) strlen(quote), FileListNodeContext(0,0,0,0), false);
  49. const char *sendResult=emailSender.Send(mailServer,
  50. hostPort,
  51. senderUsername,
  52. receiver,
  53. senderUsername,
  54. receiver,
  55. "Test subject.",
  56. "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",
  57. &fileList,
  58. true,
  59. password);
  60. if (sendResult!=0)
  61. printf("Send Failed! %s", sendResult);
  62. else
  63. printf("Success (probably).\n");
  64. printf("Press enter to quit.\n");
  65. char buff[256];
  66. Gets(buff,sizeof(buff));
  67. return 0;
  68. }
粤ICP备19079148号