Très bien,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox1.Text = "" Then
If Not TextBox2.Text = "" Then
If Not TextBox3.Text = "" Then
If Not TextBox5.Text = "" Then
If Not ComboBox1.Text = "" Then
If CheckBox1.Checked = True Then
If CheckBox3.Checked = True Then
Dim Thread1Start As New ThreadStart(AddressOf sendMail)
Dim Thread1 As New Thread(Thread1Start)
Thread1.IsBackground = True
Thread1.Start()
End If
End If
Else
errChamp()
End If
Else
errChamp()
End If
Else
errChamp()
End If
Else
errChamp()
End If
Else
errChamp()
End If
End Sub
Voilà, c’était pour le bouton et le reste:
Sub errChamp()
MessageBox.Show("Erreur, tout les champs ne sont pas complétés", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
Sub sendMail()
Invoke(New MethodInvoker(Sub()
While My.Settings.mailSend = 0
Try
Dim mail As New MailMessage
Dim SMTP As New SmtpClient
If ComboBox1.SelectedItem = ComboBox1.Items(0) Then
SMTP = New SmtpClient("smtp.gmail.com")
SMTP.Port = "587"
End If
mail.From = New MailAddress(TextBox1.Text)
mail.To.Add(TextBox3.Text)
mail.Subject = TextBox5.Text
mail.Body = RichTextBox1.Text
If Not TextBox7.Text = "" Then
Try
Dim mailAtt = New Net.Mail.Attachment(TextBox7.Text)
mail.Attachments.Add(mailAtt)
Catch ex As Exception
MessageBox.Show("Erreur, " & ex.ToString, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
SMTP.EnableSsl = True
SMTP.Send(mail)
My.Settings.mailSend = 1
My.Settings.Save()
if My.Settings.mailSend = 1 Then
MsgBox("Mail envoyer !")
End If
Me.Refresh()
Catch ex As Exception
MessageBox.Show("Erreur, " & ex.ToString, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End While
End Sub))
End Sub