From fb142d4cefe76181047409726c2f33be86a1b693 Mon Sep 17 00:00:00 2001 From: Digital Data - Marlon Schreiber Date: Thu, 14 Mar 2019 22:28:37 +0100 Subject: [PATCH] msemail2 --- DD_CommunicationService/MyComService.vb | 14 +++++----- Message/Email.vb | 34 +++++++++++-------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/DD_CommunicationService/MyComService.vb b/DD_CommunicationService/MyComService.vb index 520f783a..6031afe7 100644 --- a/DD_CommunicationService/MyComService.vb +++ b/DD_CommunicationService/MyComService.vb @@ -134,10 +134,14 @@ Public Class MyComService oAttachment = String.Empty Else oAttachment = oEmail_Row.Item("EMAIL_ATTMT1") - End If - - _Logger.Debug("Email Attachment is: {0}", oAttachment.ToString) + If File.Exists(oAttachment) = False Then + _Logger.Warn($"Email Attachment FileNotFound Exception!") + Exit Sub + Else + _Logger.Info("Email Attachment is: {0}", oAttachment.ToString) + End If + End If Dim link As String = "pmo://" & oJOB_ID & "-" & oEmail_Row.Item("REFERENCE1") If oBody.Contains("[%PMOLINK_GER]") Then oBody = oBody.Replace("[%PMOLINK_GER]", "hier") @@ -147,9 +151,7 @@ Public Class MyComService oBody = oBody.Replace("[%PMOLINK_US]", "here") End If - - - If _Email.NewEmail(oEmailTo, oSubject, oBody, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEDMI_ComService", oAttachment) = True Then + If _Email.NewEmail(oEmailTo, oSubject, oBody, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEDMI_ComService", oAttachment.ToString) = True Then Dim upd = "UPDATE TBEDM_EMAIL_QUEUE SET EMAIL_SENT = CURRENT_TIMESTAMP WHERE GUID = " & oGUID _firebird.ExecuteNonQuery(upd) End If diff --git a/Message/Email.vb b/Message/Email.vb index 198f8a9d..767a1d6a 100644 --- a/Message/Email.vb +++ b/Message/Email.vb @@ -131,7 +131,7 @@ Public Class Email End Function Public Function NewEmail(mailto As String, mailSubject As String, mailBody As String, mailfrom As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String, - AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attment As String = "", Optional Test As Boolean = False) + 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() @@ -177,25 +177,21 @@ Public Class Email Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(mymesssage.Body) htmlView.ContentType = New System.Net.Mime.ContentType("text/html") mymesssage.AlternateViews.Add(htmlView) - attment = attment.Replace("W:\", "\\windream\objects\") - If attment <> String.Empty Then - If System.IO.File.Exists(attment) Then - _logger.Info("Attachment Path is: {0}", attment) - Dim oAttachment As New System.Net.Mail.Attachment(attment) + _logger.Debug($"attachmentString [{attachmentString}]") + If attachmentString <> "" Then + _logger.Info($"Attachment Path is: {attachmentString}") + Dim oAttachment As New System.Net.Mail.Attachment(attachmentString) - 'If attment.ToLower.EndsWith("pdf") Then - ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "pdf") - 'ElseIf attment.ToLower.EndsWith("jpg") Then - ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "jpg") - 'ElseIf attment.ToLower.EndsWith("docx") Then - ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "MS-word") - 'End If - mymesssage.Attachments.Add(oAttachment) - Else - _logger.Warn($"Attachment {attment.ToString} is not existing - Mail won't be send!") - oError = True - - End If + 'If attment.ToLower.EndsWith("pdf") Then + ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "pdf") + 'ElseIf attment.ToLower.EndsWith("jpg") Then + ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "jpg") + 'ElseIf attment.ToLower.EndsWith("docx") Then + ' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "MS-word") + 'End If + mymesssage.Attachments.Add(oAttachment) + Else + _logger.Debug("No Attachment.") End If _logger.Debug($"mailfrom [{mailfrom}]")