Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Web;
- using System.Net.Mail;
- using System.IO;
- using System.Windows.Forms;
- namespace CoolAI
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- string messageToSend;
- string emailAdress;
- string username;
- string password;
- string appPath;
- // 1st line = username, 2nd = password
- string[] file = new string[2];
- public MainWindow()
- {
- appPath = @"C:\Users\Xander Kakris\source\repos\CoolAI\MessagingAppLoginForm\bin\Debug";
- InitializeComponent();
- file = File.ReadAllLines(appPath + @"\account.txt");
- username = file[0];
- password = file[1];
- // DebugMessage(appPath + @"\account.txt");
- }
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- // Ignore
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- // Send Button Clicked
- if (EmailAdressBox.Text == "" || MessageBox.Text == "")
- {
- DebugMessage("Input Field/s Empty");
- }
- else
- {
- messageToSend = MessageBox.Text;
- emailAdress = EmailAdressBox.Text;
- SendMessage(emailAdress, messageToSend);
- }
- }
- public void DebugMessage(string message)
- {
- DebugBox.Text += message;
- }
- // ********************************
- public void SendMessage(string emailAdress, string message)
- {
- try
- {
- MailMessage mail = new MailMessage(username, emailAdress, SubjectBox.Text, message);
- SmtpClient client = new SmtpClient("smtp.gmail.com");
- client.UseDefaultCredentials = false;
- client.Port = 456; //or 587
- client.Credentials = new System.Net.NetworkCredential(username, password);
- client.EnableSsl = true;
- client.Send(mail);
- DebugMessage("Mail Sent");
- } catch(Exception ex)
- {
- DebugMessage(ex.InnerException.ToString());
- }
- }
- // ********************************
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement