我有一个Windows服务,它通过从数据库中检索记录来发送电子邮件。 Windows服务运行的服务帐户是该计算机上的本地管理员。我遇到的问题是某种程度上Windows服务设法发送一些电子邮件与pdf附件存在于Windows服务所在的本地服务器上,对于大多数人我收到一条错误消息:
Invalid Mail Attachment可能导致它的真正困难是什么?我应该从哪里开始看?
由于
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
答案 0 :(得分:0)
抱歉,伙计们,因为我已经找到答案,这是我的错,因为我在不同的服务器上运行两个不同版本的Windows服务,他们都从数据库中获取附件,并且路径存在于一台服务器上保存文件的位置,而不是其他服务器上的文件,这就是为什么有些电子邮件被管理好发送的原因。