TaskFlow/app/TaskFlow/ClassEmail.vb

68 lines
3.3 KiB
VB.net

Imports System.Net.Mail
Public Class ClassEmail
Public 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) */
Dim logfile As String = LOGCONFIG.LogFile
If logfile.Contains("\\") Then
logfile = logfile.Replace("\\", "\")
End If
If IO.File.Exists(logfile) Then
Dim Attachment As Attachment = New Attachment(logfile)
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 test = True Then
MsgBox("TestMail sent successfully!", MsgBoxStyle.Information, "Success:")
End If
If Log = True Then
MsgBox("The Support-Email has been sent successfully!", MsgBoxStyle.Information, "Success:")
End If
'LOGGER.Info(">> Support/Log Email erfolgreich an " & _mailempfaenger & " versendet!", False)
Next
Return True
Catch ex As Exception
LOGGER.Error(ex)
LOGGER.Info("### Error in Mailversand: " & ex.Message)
Return False
End Try
End Function
End Class