Question

I have a windows service that sends out emails by retriving the records from the database. The service account Windows Service is running under, is a Local admin on that machine. The issue i am having is somehow the windows service manages to send out some emails with pdf attachements that exist on the local server where windows service is located and for most of them i get an error message:

Invalid Mail Attachment
and having real difficulties what could be causing it? any idea on where should i start looking please?

Thanks

Try

        ' Initialize new mail message class
        Dim objEmailMessage As New System.Net.Mail.MailMessage(EmailOutboxEntity.EmailFrom, EmailOutboxEntity.EmailTo)

        ' Set the email parameters
        objEmailMessage.Subject = EmailOutboxEntity.EmailSubject
        objEmailMessage.Body = EmailOutboxEntity.EmailBody

        ' Check if attachments have been specified
        If Not EmailOutboxEntity.TestOriginalFieldValueForNull(EmailOutboxFieldIndex.EmailAttachements) Then

            ' Get an array of attachment file names to send
            Dim arrAttachment As String() = Split(EmailOutboxEntity.EmailAttachements, CONST_AttachmentSeparator)

            ' Step through each filename and attach it to the email
            For Each strAttachment As String In arrAttachment

                ' Attach the current file to the email
                objEmailMessage.Attachments.Add(New System.Net.Mail.Attachment(strAttachment))

            Next

        End If

        ' Set the SMTP server
        Dim mailServer As New System.Net.Mail.SmtpClient(pstrSMTPServer)

        ' Send the message
        mailServer.Send(objEmailMessage)

    Catch errException As Exception

        ' Throw an exception indicating the email failed to send
        Throw New EmailOutboxManagerException(errException.Message, "Test Failed to send email, got the following error instead:")

    End Try
Was it helpful?

Solution

Sorry Guys, as i have figured out the answer and it was my fault because i was running two different versions of the windows service on different servers and they were both picking up the attachments from the database and the path existed on one server where the files were saved and not on the other server and that's why some of the emails were managed to be sent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top