這段代碼在localhost/IIS express上完美工作。我收到附帶pdf的電子郵件。但是,當我將它複製到我的服務器IIS7時,它會失敗。任何想法爲什麼?爲什麼此電子郵件附件在我的asp.net服務器上失敗,但不在本地主機上?
var db = new DirectCellarsModel();
var status = false;
MailAddress from = new MailAddress(EMAIL_SENDER);
MailAddress to = new MailAddress(recipient);
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = messageBody;
if (pdf)
{
Attachment data = new Attachment(@"C:\develop\PDF\myfree.pdf", MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
}
SmtpClient client = new SmtpClient(SMTP_CLIENT);
這是錯誤消息:
The device is not ready.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The device is not ready.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
IOException: The device is not ready.
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1093
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +886
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +127
System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) +104
你能發佈錯誤信息嗎? –
對不起,只是想忘記。試圖加載PDF文件時,「設備未準備就緒」。 –
好的......問題解決了。我重新編譯了本地開發框中的所有內容,並將其重新部署到服務器。它已經開始工作,經過5-6次嘗試......不知道爲什麼,但是嘿,它的工作...... –