【问题标题】:Invalid Mail Attachment无效的邮件附件
【发布时间】:2023-03-08 00:06:02
【问题描述】:

我有一个 Windows 服务,它通过从数据库中检索记录来发送电子邮件。运行 Windows 服务的服务帐户是该计算机上的本地管理员。我遇到的问题是 Windows 服务以某种方式设法发送一些带有 pdf 附件的电子邮件,这些电子邮件存在于 Windows 服务所在的本地服务器上,并且对于其中大多数我收到一条错误消息:

无效的邮件附件
并且遇到真正的困难可能是什么原因造成的?请问我应该从哪里开始寻找任何想法?

谢谢

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

【问题讨论】:

  • 服务代码将是一个很好的开始。
  • 已按照您的要求提供了上述代码。
  • 在循环和添加附件的地方,尝试取出整个:New System.Net.Mail.Attachment,然后放入您的 strAttachment。
  • 我可以尝试这样做,但是我想问一下是否存在无效附件是否会引发异常?
  • 是的,它会,但它可能源于很多事情......你可以发布问题的堆栈跟踪吗?

标签: vb.net email windows-services


【解决方案1】:

对不起,伙计们,我已经找到了答案,这是我的错,因为我在不同的服务器上运行了两个不同版本的 Windows 服务,它们都从数据库中获取附件,并且路径存在于一台服务器上文件保存在哪里,而不是在另一台服务器上,这就是为什么一些电子邮件被设法发送的原因。

【讨论】:

    猜你喜欢
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多