if (this.attachmentsListbox.Items.Count > 0)

{

    this.AddLogEntry("Creating message.");

 

    // We create the message object

    ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();

 

    // We assign the sender email

    message.From.Email = this.fromEmailTextbox.Text;

 

    // We assign the recipient email

    message.To.Add(this.toEmailTextbox.Text);

 

    // We assign the subject

    message.Subject = this.subjectTextbox.Text;

 

    // We assign the body text

    message.BodyText.Text = this.bodyTextTextbox.Text;

 

    // We now add each attachments

    foreach (string attachmentPath in this.attachmentsListbox.Items)

    {

        message.Attachments.Add(attachmentPath, false);

    }

 

    // We send the email using the specified SMTP server

    this.AddLogEntry("Sending message.");

 

    try

    {

        message.Send(this.smtpServerAddressTextbox.Text);

 

        this.AddLogEntry("Message sent successfully.");

    }

    catch (SmtpException ex)

    {

        this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));

    }

    catch (Exception ex)

    {

        this.AddLogEntry(string.Format("Failed: {0}", ex.Message));

    }

}

 

else

{

    MessageBox.Show("Please add an attachment before sending this test message.");

}