{ // Collect user input from the form and stow content into // the objects member variables string tb1, tb2; tb1 = textBox1.Text; tb2 = comboBox1.SelectedItem.ToString(); mTo1 = tb1.Trim() + tb2.Trim(); mFrom = (textBox2.Text).Trim(); mSubject = (textBox3.Text).Trim(); mMailServer = (textBox4.Text).Trim(); mMsg = (textBox5.Text).Trim(); // Within a try catch, format and send the message to // the recipient. Catch and handle any errors. try { MailMessage message = new MailMessage(mFrom, mTo1, mSubject, mMsg); SmtpClient mySmtpClient = new SmtpClient(mMailServer); mySmtpClient.UseDefaultCredentials = true; mySmtpClient.Send(message); MessageBox.Show("Message Sent"); } catch (FormatException ex) { MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SmtpException ex) { MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)