TaskFlow/DD_PM_WINDREAM/ClassEmail.vb
Digital Data - Marlon Schreiber c987d877a3 MSBuildProblem_PM
2017-04-03 11:23:11 +02:00

66 lines
3.4 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 = ClassLogger.logDateiname
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("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
'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