Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Web;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.IO;
- using System.Net.Mail;
- using Microsoft.Win32;
- using System.Threading;
- using System.Diagnostics;
- namespace AlienBlob_s_Mailer
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public static string selEmail = "";
- public static string selsmtp = "";
- public static string selpassword = "";
- private void AlienBlobMailer_Load(object sender, EventArgs e)
- {
- InformationWindow.ReadOnly = true;
- FileLoader.RunWorkerAsync();
- if(!Directory.Exists(Application.StartupPath + "\\Data"))
- {
- Directory.CreateDirectory(Application.StartupPath + "\\Data");
- Directory.CreateDirectory(Application.StartupPath + "\\Data\\Adressbook");
- Directory.CreateDirectory(Application.StartupPath + "\\Data\\Saved Mails");
- Directory.CreateDirectory(Application.StartupPath + "\\Data\\User Info");
- }
- }
- private void SenderWorker_DoWork(object sender, DoWorkEventArgs e)
- {
- try
- {
- MailMessage mail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient(Smtp.Text, 587);
- SmtpServer.UseDefaultCredentials = false;
- SmtpServer.Credentials = new NetworkCredential(UserAdress.Text, Password.Text);
- SmtpServer.EnableSsl = true;
- foreach (string mailAddr in Recipients.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
- {
- mail.To.Add(mailAddr);
- }
- mail.From = new MailAddress (UserAdress.Text);
- mail.Subject = Subject.Text;
- mail.Body = TheMail.Text;
- SmtpServer.Send(mail);
- InformationWindow.Text = InformationWindow.Text + Environment.NewLine + ("[") + DateTime.Now.ToString("HH:mm:ss tt") + ("] ") + (" Email sent...");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Error: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
- InformationWindow.Text = InformationWindow.Text + Environment.NewLine + ("[") + DateTime.Now.ToString("HH:mm:ss tt") + ("] ") + (" Email not sent...");
- }
- finally
- {
- }
- }
- private void SendMailBtn_Click(object sender, EventArgs e)
- {
- SenderWorker.RunWorkerAsync();
- InformationWindow.Text = InformationWindow.Text + Environment.NewLine + ("[") + DateTime.Now.ToString("HH:mm:ss tt") + ("] ") + (" Sending Email...");
- }
- private void SaveUser_Click(object sender, EventArgs e)
- {
- try
- {
- StreamWriter abc = new StreamWriter(Application.StartupPath + "\\Data\\User Info\\" + User.Text + ".dll", true);
- abc.WriteLine(User.Text);
- abc.WriteLine(UserAdress.Text);
- abc.WriteLine(Password.Text);
- abc.WriteLine(Smtp.Text);
- abc.Dispose();
- abc.Close();
- cbUser.Items.Clear();
- FileLoader.RunWorkerAsync();
- FileStream fs = new FileStream(Application.StartupPath + "\\Data\\User Info\\" + User.Text + ".dll", FileMode.Create, FileAccess.Write);
- StreamWriter s = new StreamWriter(fs);
- s.BaseStream.Seek(0, SeekOrigin.End);
- s.WriteLine("<username>" + User.Text + "</username>");
- s.WriteLine("<mail>" + UserAdress.Text + "</mail>");
- s.WriteLine("<password>" + Password.Text + "</password>");
- s.WriteLine("<smtp>" + Smtp.Text + "</smtp>");
- s.Close();
- }
- catch (Exception ex)
- {
- }
- }
- private void SaveRecipientBtn_Click(object sender, EventArgs e)
- {
- try
- {
- StreamWriter abc = new StreamWriter(Application.StartupPath + "\\Data\\Adressbook\\adressbook.dll", true);
- abc.WriteLine(Recipients.Text);
- abc.Dispose();
- abc.Close();
- cbadressbook.Items.Clear();
- FileLoader.RunWorkerAsync();
- }
- catch (Exception ex)
- {
- }
- }
- private void LoadAllRecipientsBtn_Click(object sender, EventArgs e)
- {
- try
- {
- if (File.Exists(Application.StartupPath + "\\Data\\Adressbook\\adressbook.dll"))
- {
- StreamReader fileSR = new StreamReader(Application.StartupPath + "\\Data\\Adressbook\\adressbook.dll");
- Recipients.Text = (fileSR.ReadToEnd());
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void SaveMailsBtn_Click(object sender, EventArgs e)
- {
- try
- {
- StreamWriter abc = new StreamWriter(Application.StartupPath + "\\Data\\Saved Mails\\" + SavedMails.Text + ".dll", true);
- abc.WriteLine(Subject.Text);
- abc.Dispose();
- abc.Close();
- cbSavedMails.Items.Clear();
- FileLoader.RunWorkerAsync();
- FileStream fs = new FileStream(Application.StartupPath + "\\Data\\Saved Mails\\" + SavedMails.Text + ".dll", FileMode.Create, FileAccess.Write);
- StreamWriter s = new StreamWriter(fs);
- s.BaseStream.Seek(0, SeekOrigin.End);
- s.WriteLine("<mailsubject>" + Subject.Text + "</mailsubject>");
- s.WriteLine("<mailbody>" + TheMail.Text + "</mailbody>");
- s.Close();
- SavedMails.Clear();
- }
- catch (Exception ex)
- {
- }
- }
- private void cbUser_SelectedIndexChanged(object sender, EventArgs e)
- {
- string bbb = File.ReadAllText(Application.StartupPath + "\\Data\\User Info\\" + cbUser.SelectedItem);
- string[] accountUsername = bbb.Split(new String[] {"<username>", "</username>"}, StringSplitOptions.None);
- string[] accountMail = bbb.Split(new String[] { "<mail>", "</mail>" }, StringSplitOptions.None);
- string[] accountPassword = bbb.Split(new String[] { "<password>", "</password>" }, StringSplitOptions.None);
- string[] accountSmtp = bbb.Split(new String[] { "<smtp>", "</smtp>" }, StringSplitOptions.None);
- User.Text = accountUsername[1];
- UserAdress.Text = accountMail[1];
- Password.Text = accountPassword[1];
- Smtp.Text = accountSmtp[1];
- }
- private void cbadressbook_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- if(!Recipients.Text.Contains("@"))
- {
- Recipients.Text = cbadressbook.Text;
- }
- else
- Recipients.Text = Recipients.Text + Environment.NewLine + cbadressbook.Text;
- }
- catch (Exception ex)
- {
- }
- }
- private void cbSavedMails_SelectedIndexChanged(object sender, EventArgs e)
- {
- string bbb = File.ReadAllText(Application.StartupPath + "\\Data\\Saved Mails\\" + cbSavedMails.Text);
- string[] mailSubject = bbb.Split(new String[] { "<mailsubject>", "</mailsubject>" }, StringSplitOptions.None);
- string[] mailBody = bbb.Split(new String[] { "<mailbody>", "</mailbody>" }, StringSplitOptions.None);
- TheMail.Text = mailBody[1];
- Subject.Text = mailSubject[1];
- }
- private void emptyAllFieldsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- User.Clear();
- TheMail.Clear();
- UserAdress.Clear();
- Password.Clear();
- Smtp.Clear();
- Recipients.Clear();
- Subject.Clear();
- SavedMails.Clear();
- }
- private void troubleshootingToolStripMenuItem_Click(object sender, EventArgs e)
- {
- AlienBlobMailerHelp TroubleShoot = new AlienBlobMailerHelp();
- TroubleShoot.Show();
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void FileLoader_DoWork(object sender, DoWorkEventArgs e)
- {
- cbUser.Items.Clear();
- cbadressbook.Items.Clear();
- cbSavedMails.Items.Clear();
- try
- {
- DirectoryInfo di = new DirectoryInfo(Application.StartupPath + "\\Data\\User Info\\");
- FileSystemInfo[] fi = di.GetFiles();
- Console.WriteLine(Application.StartupPath + "\\Data\\User Info\\");
- foreach (FileInfo fiTemp in fi)
- cbUser.Items.Add(fiTemp.Name);
- string[] folderFiles = Directory.GetFiles(Application.StartupPath + "\\Data\\User Info\\");
- if (folderFiles.Length > 0)
- {
- InformationWindow.Text = ("[") + DateTime.Now.ToString("HH:mm:ss tt") + ("] ") + (" AlienBlob's Mailer loaded users without problems...");
- }
- else
- {
- InformationWindow.Text = ("[") + DateTime.Now.ToString("HH:mm:ss tt") + ("] ") + (" AlienBlob's Mailer did not find any users...");
- }
- if (File.Exists(Application.StartupPath + "\\Data\\Adressbook\\adressbook.dll"))
- {
- StreamReader fileSR = new StreamReader(Application.StartupPath + "\\Data\\Adressbook\\adressbook.dll");
- string line;
- while ((line = fileSR.ReadLine()) != null)
- {
- cbadressbook.Items.Add(line);
- }
- }
- }
- catch (Exception ex)
- {
- }
- try
- {
- DirectoryInfo di = new DirectoryInfo(Application.StartupPath + "\\Data\\Saved Mails\\");
- FileSystemInfo[] fie = di.GetFiles();
- Console.WriteLine(Application.StartupPath + "\\Data\\Saved Mails\\");
- foreach (FileInfo fieTemp in fie)
- cbSavedMails.Items.Add(fieTemp.Name);
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment