전자 메일을 보내기 위해 smtp 클라이언트로 google을 사용하고 있으며 첨부 파일을 보내는 데 문제가 있습니다. asp : fileupload를 사용하여 fileupload.filename을 사용하여 파일을 선택합니다. 첨부 파일을 선택하십시오. 다음은 오류 메시지입니다.System.IO.FileNotFoundException 파일을 찾을 수 없습니다.
System.IO.FileNotFoundException : 'C : \ Program Files (x86) \ IIS Express \ ISO Certificate.pdf'파일을 찾을 수 없습니다. 파일 이름 : System.IO.FileStream.Init의 Error.WinIOError (Int32 errorCode, String maybeFullPath) (문자열 경로, FileMode 모드)에서 System.IO의 'C : \ Program Files \ x86 Express \ ISO Certificate.pdf' , FileAccess 액세스, Int32 권한, 부울 useRights, FileShare 공유, Int32 bufferSize, FileOptions 옵션, SECURITY_ATTRIBUTES secAttrs, String msgPath, 부울 bFromProxy, 부울 useLongPath, 부울 checkHost) System.IO.FileStream..ctor (String path, FileMode mode, FileAccess 액세스, FileShare 공유)에서 System.Net.Mail.AttachmentBase.SetContentFromFile (String fileName, String mediaType) System.Net.Mail.AttachmentBase..ctor (String fileName) C : \ Users \ jack \ Documents \ Visual Studio 2013 \ WebSites \ firstarPrecision \ frmQuote.aspx.cs에있는 frmQuote.btnSubmit_Click (개체 보낸 사람, EventArgs e)의 문자열 fileName) : 줄 46
그런 다음 여기 코드가
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("EMAIL", "PASSWORD"),
EnableSsl = true
};
var msgQuote = new MailMessage
{
Subject = strQuoteSubject,
Body = strQuoteBody,
From = new MailAddress("EMAIL"),
};
//HINT HINT HERE IS WHERE THE ERROR OCCURS, I JUST DONT KNOW WHY :(
//HOW DO I TURN OFF CAPS LOCK
Attachment att = new Attachment(fupAttachment.FileName.ToString());
msgQuote.Attachments.Add(att);
msgQuote.To.Add(new MailAddress(strEmail));
client.Send(msgQuote);
}
catch (Exception ex)
{
Response.Write(ex);
}
과 함께 갈 수있는 C# 코드입니다, 내가 분명히 내 자격 증명을 차단 등은 ... 적어도 나는 그것을 모두를 얻었기를 바랍니다.
'fupAttachment.FileName'은 파일 경로가 아닙니다. 업로드 된 바이트를 전달해야합니다. – SLaks