Ik heb ook een Mail functie, die bij mij onderdeel uitmaakt van een groter project, maar je mag hem gerust even doorneuzen. Ik doe het wel in het engels dus dan moet je dat even accepteren

[CPP]Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If My.Computer.Network.IsAvailable = True Then
Try
If TextBox1.Text = "" Then
Label1.ForeColor = Color.Red
End If
If TextBox2.Text = "" Then
Label2.ForeColor = Color.Red
End If
If TextBox3.Text = "" Then
Label3.ForeColor = Color.Red
End If
If TextBox4.Text = "" Then
Label5.ForeColor = Color.Red
End If
If RichTextBox1.Text = "" Then
Label4.ForeColor = Color.Red
End If
If TextBox1.Text.Contains("@gmail.com") Then
Dim mail As New MailMessage
mail.From = New MailAddress(TextBox1.Text)
mail.To.Add(TextBox4.Text)
mail.Subject = TextBox3.Text
mail.Body = RichTextBox1.Text
Dim smtp As New SmtpClient("smtp.gmail.com")
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
smtp.Port = "587"
smtp.Send(mail)
MsgBox("Mail sent to: " & TextBox4.Text)
Me.Close()
ElseIf TextBox1.Text.Contains("@hotmail.com") Or TextBox1.Text.Contains("@live.nl") Or TextBox1.Text.Contains("@hotmail.nl") Then
Dim mail As New MailMessage
mail.From = New MailAddress(TextBox1.Text)
mail.To.Add(TextBox4.Text)
mail.Subject = TextBox3.Text
mail.Body = RichTextBox1.Text
Dim smtp As New SmtpClient("smtp.live.com")
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
smtp.Port = "587"
smtp.Send(mail)
MsgBox("Mail sent to: " & TextBox4.Text)
Me.Close()
Else
MsgBox("Invalid email address. Only hotmail and gmail are supported.")
End If
Catch ex As Exception
MsgBox("An error occurred while sending the email. Please check your connection settings and try again.")
End Try
Else
MsgBox("There is no connection to the Internet. Check your settings and try again.")
End If
End Sub[/CPP]