Commit
This commit is contained in:
@@ -6,6 +6,7 @@ Imports Independentsoft.Email.Imap
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.Net.Mail
|
||||
Imports System.Net
|
||||
Imports System.Security
|
||||
|
||||
Public Class Email
|
||||
Private _logger As Logging.Logger
|
||||
@@ -133,7 +134,6 @@ Public Class Email
|
||||
mailfrom As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String,
|
||||
AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attachmentString As String = "", Optional Test As Boolean = False)
|
||||
Try
|
||||
Dim oError As Boolean = False
|
||||
Dim oReceipiants As String()
|
||||
If mailto.Contains(";") Then
|
||||
oReceipiants = mailto.Split(";")
|
||||
@@ -141,42 +141,42 @@ Public Class Email
|
||||
ReDim Preserve oReceipiants(0)
|
||||
oReceipiants(0) = mailto
|
||||
End If
|
||||
_logger.Debug($"mailsmtp [{mailsmtp}]")
|
||||
_logger.Debug($"mailfrom [{mailfrom}]")
|
||||
_logger.Debug($"mailport [{mailport}]")
|
||||
For Each oMailReceipiant As String In oReceipiants
|
||||
_logger.Debug($"oMailReceipiant [{oMailReceipiant}]")
|
||||
_logger.Debug($"mailsmtp [{mailsmtp}]")
|
||||
Dim sClient As Net.Mail.SmtpClient
|
||||
Try
|
||||
sClient = New Net.Mail.SmtpClient(mailsmtp, mailport)
|
||||
Catch ex As Exception
|
||||
_logger.Warn($"Could not create SMTP-Client: [{ex.Message}]")
|
||||
Return False
|
||||
End Try
|
||||
sClient.DeliveryMethod = SmtpDeliveryMethod.Network
|
||||
|
||||
Dim mymesssage As New MailMessage
|
||||
sClient.Port = mailport
|
||||
_logger.Debug($"mailport [{mailport}]")
|
||||
Dim oSmtp_Server As New Mail.SmtpClient
|
||||
Dim oE_mail As New MailMessage()
|
||||
oSmtp_Server.UseDefaultCredentials = False
|
||||
oSmtp_Server.Credentials = New Net.NetworkCredential(mailUser, mailPW)
|
||||
oSmtp_Server.Port = mailport
|
||||
If AUTH_TYPE = "SSL" Then
|
||||
_logger.Debug("SSL = true")
|
||||
sClient.EnableSsl = True
|
||||
oSmtp_Server.EnableSsl = True
|
||||
Else
|
||||
_logger.Debug("SSL = false")
|
||||
sClient.EnableSsl = False
|
||||
oSmtp_Server.EnableSsl = False
|
||||
End If
|
||||
_logger.Debug($"mailUser [{mailUser}]")
|
||||
sClient.Credentials = New NetworkCredential(mailUser, mailPW)
|
||||
sClient.UseDefaultCredentials = False
|
||||
|
||||
oSmtp_Server.Host = mailsmtp
|
||||
|
||||
oE_mail = New MailMessage()
|
||||
oE_mail.From = New MailAddress(mailfrom)
|
||||
oE_mail.To.Add(oMailReceipiant)
|
||||
oE_mail.Subject = mailSubject
|
||||
oE_mail.IsBodyHtml = False
|
||||
If Test = True Then
|
||||
mymesssage.Body = $"This is the body (text will be replaced within profile)! <br> mailsmtp: {mailsmtp} <br> mailport: {mailport} <br> mailUser: {mailUser} <br> mailPW: XXXX <br> AUTH_TYPE: {AUTH_TYPE}"
|
||||
oE_mail.Body = $"This is the body (text will be replaced within profile)! <br> mailsmtp: {mailsmtp} <br> mailport: {mailport} <br> mailUser: {mailUser} <br> mailPW: XXXX <br> AUTH_TYPE: {AUTH_TYPE}"
|
||||
Else
|
||||
mymesssage.Body = mailBody
|
||||
oE_mail.Body = mailBody
|
||||
End If
|
||||
_logger.Debug($"mailBody [{mailBody}]")
|
||||
'mymesssage.IsBodyHtml = True
|
||||
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(mymesssage.Body)
|
||||
oE_mail.IsBodyHtml = True
|
||||
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(oE_mail.Body)
|
||||
htmlView.ContentType = New System.Net.Mime.ContentType("text/html")
|
||||
mymesssage.AlternateViews.Add(htmlView)
|
||||
oE_mail.AlternateViews.Add(htmlView)
|
||||
_logger.Debug($"attachmentString [{attachmentString}]")
|
||||
If attachmentString <> "" Then
|
||||
_logger.Info($"Attachment Path is: {attachmentString}")
|
||||
@@ -189,29 +189,20 @@ Public Class Email
|
||||
'ElseIf attment.ToLower.EndsWith("docx") Then
|
||||
' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "MS-word")
|
||||
'End If
|
||||
mymesssage.Attachments.Add(oAttachment)
|
||||
oE_mail.Attachments.Add(oAttachment)
|
||||
Else
|
||||
_logger.Debug("No Attachment.")
|
||||
End If
|
||||
_logger.Debug($"mailfrom [{mailfrom}]")
|
||||
|
||||
mymesssage.From = New MailAddress(mailfrom)
|
||||
_logger.Debug($"mailSubject [{mailSubject}]")
|
||||
mymesssage.Subject = mailSubject
|
||||
mymesssage.To.Add(New MailAddress(oMailReceipiant))
|
||||
_logger.Debug($"Now Sending mail...")
|
||||
sClient.Send(mymesssage)
|
||||
oSmtp_Server.Send(oE_mail)
|
||||
_logger.Debug($"Mail has been sent!")
|
||||
_logger.Info("Message to " & oMailReceipiant & " has been send.")
|
||||
Next
|
||||
If oError = False Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return True
|
||||
|
||||
Catch error_t As Exception
|
||||
_logger.Error(error_t)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
|
||||
Reference in New Issue
Block a user