Imports System.Net.Mail

Public Class ClassEmail
    Public Shared Function Send_Log_Mail(ByVal vBody As String, ByVal vBetreff As String, ByVal emailfrom As String, ByVal emailsmtp As String, ByVal emailuser As String, ByVal emailpw As String, ByVal email_empf As String, Optional test As Boolean = False, Optional Log As Boolean = False)
        '#### E-MAIL NACHRICHT VERSENDEN
        Try
            Dim empfaenger As String()
            If email_empf.Contains(";") Then
                empfaenger = email_empf.Split(";")
            Else
                ReDim Preserve empfaenger(0)
                empfaenger(0) = email_empf
            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(emailfrom, _mailempfaenger, vBetreff & " - Domain: " & Environment.UserDomainName, _
                                               "<font face=""Arial"">" & vBody & "<br>>> Version: " & My.Application.Info.Version.ToString & "<br>>> Maschine: " & Environment.MachineName & "<br>" & "<br>>> Domain-Name: " & Environment.UserDomainName & "<br>" & _
                                               "<br>>> Gesendet am: " & My.Computer.Clock.LocalTime.ToShortDateString & " " & _
                                               My.Computer.Clock.LocalTime.ToLongTimeString & "</font>")
                If test = False Then
                    If Log = True Then
                        ' create and add the attachment(s) */
                        If ClassLogger.logDateiname.Contains("\\") Then
                            ClassLogger.logDateiname = ClassLogger.logDateiname.Replace("\\", "\")
                        End If
                        If IO.File.Exists(ClassLogger.logDateiname) Then
                            Dim Attachment As Attachment = New Attachment(ClassLogger.logDateiname)
                            message.Attachments.Add(Attachment)
                        End If
                    End If
                End If

                With message
                    .IsBodyHtml = True
                    .Priority = MailPriority.High
                End With

                'Einen SMTP Client erzeugen und Anmeldungsinformationen hinterlegen
                Dim emailClient As New SmtpClient(emailsmtp)
                'Email mit Authentifizierung
                Dim SMTPUserInfo As New System.Net.NetworkCredential(emailuser, emailpw) ', My.Settings.vDomain)
                emailClient.UseDefaultCredentials = False
                emailClient.Credentials = SMTPUserInfo
                emailClient.Port = 25

                '*Send the message */
                emailClient.Send(message)
                If USER_LANGUAGE = "de-DE" Then
                    If test = True Then
                        MsgBox("Die Test-Email wurde erfolgreich versendet!", MsgBoxStyle.Information, "Erfolgsmeldung:")
                    End If
                    If Log = True Then
                        MsgBox("Die Support-Email wurde erfolgreich versendet!", MsgBoxStyle.Information, "Erfolgsmeldung:")
                    End If
                Else
                    If test = True Then
                        MsgBox("Test-Email sucessfully sent!", MsgBoxStyle.Information, "Success:")
                    End If
                    If Log = True Then
                        MsgBox("Support-Email sucessfully sent!", MsgBoxStyle.Information, "Success:")
                    End If
                End If
                'ClassLogger.Add(">> Support/Log Email erfolgreich an " & _mailempfaenger & " versendet!", False)
            Next
            Return True
        Catch ex As Exception
            ClassLogger.Add("### Fehler im Mailversand: " & ex.Message)
            Return False
        End Try
    End Function

End Class
