Imports System.Net.Mail
Public Class ClassEmail
    Private Shared MailSSL As Boolean = False
    Public Shared Function Send_EMail(MailEmpfaenger As String, MailBetreff As String, vBody As String, MAIL_SMTP As String, MAIL_USER As String, MAIL_PW As String, MAIL_FROM As String)
        '#### E-MAIL NACHRICHT VERSENDEN
        Try
            If MAIL_SMTP <> "" And MAIL_USER <> "" Then
                Dim empfaenger As String()
                If MailEmpfaenger.Contains(";") Then
                    empfaenger = MailEmpfaenger.Split(";")
                Else
                    ReDim Preserve empfaenger(0)
                    empfaenger(0) = MailEmpfaenger
                End If
                'Für jeden Empfänger eine Neue Mail erzeugen
                For Each _mailempfaenger As String In empfaenger
                    'Neue Nachricht erzeugen: 
                    Dim message As New MailMessage(MAIL_FROM, Trim(_mailempfaenger), MailBetreff, _
                                                             "<font face=""Tahoma"">" & vBody & "<br>" & _
                                                             "<br>Creation TimeStamp: " & My.Computer.Clock.LocalTime.ToShortDateString & "-" & _
                                                             My.Computer.Clock.LocalTime.ToLongTimeString & "</font>")
                    ' create and add the attachment(s) */
                    ' Dim Attachment As Attachment = New Attachment("E:\test\Frachkostenreport.txt")
                    'message.Attachments.Add(Attachment)
                    With message
                        .IsBodyHtml = True
                    End With

                    'Einen SMTP Client erzeugen und Anmeldungsinformationen hinterlegen
                    Dim emailClient As New SmtpClient(MAIL_SMTP)
                    emailClient.EnableSsl = MailSSL
                    'Email mit Authentifizierung
                    Dim SMTPUserInfo As New System.Net.NetworkCredential(MAIL_USER, MAIL_PW) ', My.Settings.vDomain)
                    emailClient.UseDefaultCredentials = False
                    emailClient.Credentials = SMTPUserInfo
                    emailClient.Port = 25
                    '*Send the message */
                    emailClient.Send(message)
                Next
                Return True
            End If
            Return True
        Catch ex As Exception
            MsgBox("Error in Send Email: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
    End Function

End Class
