Torna al Thread
textbox text1;
textbox text2;
public void invio()
{
if (text1.Text.Length == 0 && text2.Text.Length == 0)
{
MessageBox.Show("Please Fill The \"From\" and The \"To\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (text1.Text.Length == 0)
{
MessageBox.Show("Please Fill The \"From\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (text2.Text.Length == 0)
{
MessageBox.Show("Please Fill The \"To\" Field.", "Missing", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
progressBar1.Value = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = Convert.ToInt32(comboBox2.SelectedItem.ToString());
int nom = Convert.ToInt32(comboBox2.SelectedItem.ToString());
for (int i = 0; i <= nom; i++)
{
try
{
this.Title = "UFO Mail - Sending...";
Cursor = Cursors.Wait;
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(textBox1.Text.ToString());
Msg.to.Add(new MailAddress(textBox2.Text.ToString()));
Msg.Subject = textBox3.Text.ToString();
Msg.Body = richTextBox1.Document.ToString();
Msg.IsBodyHtml = true;
SmtpClient Smtp = new SmtpClient(comboBox1.SelectedItem.ToString());
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential Credential = new NetworkCredential();
Smtp.UseDefaultCredentials = false;
Smtp.Credentials = Credential;
Smtp.Send(Msg);
progressBar1.Value = +1;
if (progressBar1.Value == nom)
{
MessageBox.Show("message Sent!", "Sent", MessageBoxButton.OK, MessageBoxImage.Information);
this.Title = "UFO Mail";
Cursor = Cursors.Arrow;
progressBar1.Value = 0;
}
}
catch
{
MessageBox.Show("Houston, We Have a Problem!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
this.Title = "UFO Mail";
Cursor = Cursors.Arrow;
progressBar1.Value = 0;
return;
}
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
// prima di avviare il thread ti salvi i riferimenti
text2 = textbox2
text1 = textbox1
Thread myThread = new Thread(new ThreadStart(invio));
myThread.Start();
}