Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Web;
  16. using System.Net.Mail;
  17. using System.IO;
  18. using System.Windows.Forms;
  19. namespace CoolAI
  20. {
  21. /// <summary>
  22. /// Interaction logic for MainWindow.xaml
  23. /// </summary>
  24. public partial class MainWindow : Window
  25. {
  26. string messageToSend;
  27. string emailAdress;
  28. string username;
  29. string password;
  30. string appPath;
  31. // 1st line = username, 2nd = password
  32. string[] file = new string[2];
  33. public MainWindow()
  34. {
  35. appPath = @"C:\Users\Xander Kakris\source\repos\CoolAI\MessagingAppLoginForm\bin\Debug";
  36. InitializeComponent();
  37. file = File.ReadAllLines(appPath + @"\account.txt");
  38. username = file[0];
  39. password = file[1];
  40. // DebugMessage(appPath + @"\account.txt");
  41.  
  42. }
  43.  
  44. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  45. {
  46. // Ignore
  47.  
  48. }
  49.  
  50. private void Button_Click(object sender, RoutedEventArgs e)
  51. {
  52. // Send Button Clicked
  53.  
  54.  
  55. if (EmailAdressBox.Text == "" || MessageBox.Text == "")
  56. {
  57. DebugMessage("Input Field/s Empty");
  58.  
  59. }
  60. else
  61. {
  62. messageToSend = MessageBox.Text;
  63. emailAdress = EmailAdressBox.Text;
  64. SendMessage(emailAdress, messageToSend);
  65. }
  66.  
  67. }
  68.  
  69. public void DebugMessage(string message)
  70. {
  71. DebugBox.Text += message;
  72. }
  73. // ********************************
  74. public void SendMessage(string emailAdress, string message)
  75. {
  76. try
  77. {
  78. MailMessage mail = new MailMessage(username, emailAdress, SubjectBox.Text, message);
  79. SmtpClient client = new SmtpClient("smtp.gmail.com");
  80. client.UseDefaultCredentials = false;
  81. client.Port = 456; //or 587
  82. client.Credentials = new System.Net.NetworkCredential(username, password);
  83. client.EnableSsl = true;
  84. client.Send(mail);
  85. DebugMessage("Mail Sent");
  86. } catch(Exception ex)
  87. {
  88. DebugMessage(ex.InnerException.ToString());
  89. }
  90.  
  91.  
  92. }
  93. // ********************************
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement