private void button2_Click(object sender, EventArgs e) { try { SaveData(); UpdateCore.Email em = UpdateCore.Email.Instance; bool sucess = em.SendEmail("Test Email", "This is a test email to check that your email is configured corectly for the Windows Update application. Check your inbox and if you received this email then all is ok"); SaveData(); MessageBox.Show("An email has been sent to your inbox as a test"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void TestEmailSend() { Init(); // For stand alone unit testing Database db = new Database(); string SQL = "SELECT SmtpHost, SmtpPort, FromEmailAddress, FromEmailDisplayName, FromPassword, DefaultSendEmail FROM dbo.[CONFIG]"; List <string> rows = db.Read(SQL, 6); string[] cols = rows[0].Split(new Database().COLUMN_DELIMETER); UpdateCore.Email email = UpdateCore.Email.Instance; email.SmtpHost = cols[0]; email.setSmtpPort(Int32.Parse(cols[1])); email.FromEmailAddress = cols[2]; email.FromEmailDisplayName = cols[3]; email.FromPassword = cols[4]; email.SendEmail(cols[5], "This is a test email", "The body of this email is blank"); }
private void SaveData() { UpdateCore.Email e = UpdateCore.Email.Instance; int Output = 0; if (!Int32.TryParse(this.SMTP_PORT.Text, out Output)) { throw new Exception("The port must a positive integer. Sorry but I can't save this data until it is changed"); } else { e.SmtpHost = this.SMTP_HOST_NAME.Text; e.setSmtpPort(Int32.Parse(this.SMTP_PORT.Text)); e.FromEmailAddress = this.FROM_EMAIL.Text; e.FromEmailDisplayName = this.FROM_DISPLAY_NAME.Text; e.FromPassword = this.FROM_PASSWORD.Text; e.setSendEmail(this.DEFAULT_SEND_EMAIL.Text); e.SaveConfig(); } }