2012-04-11 3 views
4

누구든지이 문제를 재현 할 수 있습니까? 그것은 SmtpClient (.NET 4.0)에 심각한 버그가있는 것처럼 보이지만 이전에는 아무도 보지 못했으며 Google은 비슷한 문제가있는 사용자를 표시하지 않는 것으로 보입니다.'이름'속성을 사용할 때 SmtpClient가 보낸 첨부 파일 순서가 올바르지 않습니다.

첨부 파일이 2 개 이상인 이메일을 보낼 때 'Attachment.Name'속성이 사용되면 첨부 파일의 이름이 잘못됩니다 (예 : 첨부 파일의 이름이 바뀌 었음). 해결 방법 (실제로 설정하는 올바른 속성)은 ContentDisposition.FileName을 사용하는 것입니다. 그러나 이것이 모든 사람에게 일어난다면 나는 매우 흥미가있을 것입니다. 누구든지이 문제를 재현 할 수 있습니까? 그것은 SmtpClient (.NET 4.0)에 심각한 버그가있는 것처럼 보이지만 이전에는 아무도 보지 못했으며 Google은 비슷한 문제가있는 사용자를 표시하지 않는 것으로 보입니다. 당신은 zip 파일의 몇 C로 만들어야합니다 : \ TMP \ emailin

var zipCt = new ContentType { MediaType = MediaTypeNames.Application.Zip }; 

var attachmentA = new Attachment(@"c:\tmp\emailin\a.zip", zipCt); 
attachmentA.ContentDisposition.FileName = "a.zip"; 
attachmentA.Name = "a.zip"; 

var attachmentB = new Attachment(@"c:\tmp\emailin\b.zip", zipCt); 
attachmentB.ContentDisposition.FileName = "b.zip"; 
attachmentB.Name = "b.zip"; 

var msg = new MailMessage("[email protected]", "[email protected]") 
{ 
     Body = "body", 
     Subject = "subject" 
}; 
msg.Attachments.Add(attachmentA); 
msg.Attachments.Add(attachmentB); 

using (var smtp = new SmtpClient()) 
{ 
    smtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; 
    smtp.PickupDirectoryLocation = @"c:\tmp\emailout\"; 
    smtp.Send(msg); 
} 

\ 이제 C에서 EML 파일을 보면 : \ TMP \ emailout 당신은

같은 것을 볼 수 \
X-Sender: [email protected] 
X-Receiver: [email protected] 
MIME-Version: 1.0 
From: [email protected] 
To: [email protected] 
Date: 11 Apr 2012 12:36:48 +0100 
Subject: subject 
Content-Type: multipart/mixed; boundary=--boundary_0_1b7bb1ee-ba28-4258-b662-554adb7ff81a 


----boundary_0_1b7bb1ee-ba28-4258-b662-554adb7ff81a 
Content-Type: text/plain; charset=us-ascii 
Content-Transfer-Encoding: quoted-printable 

body 
----boundary_0_1b7bb1ee-ba28-4258-b662-554adb7ff81a 
Content-Type: application/zip; name=b.zip 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=a.zip 

UEsDBAoAAAAAAG5ki0AAAAAAAAAAAAAAAAAFAAAAYS50eHRQSwECPwAKAAAAAABu 
ZItAAAAAAAAAAAAAAAAABQAkAAAAAAAAACAAAAAAAAAAYS50eHQKACAAAAAAAAEA 
GADa2JQw1xfNAdrYlDDXF80B2tiUMNcXzQFQSwUGAAAAAAEAAQBXAAAAIwAAAAAA 
----boundary_0_1b7bb1ee-ba28-4258-b662-554adb7ff81a 
Content-Type: application/zip; name=a.zip 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=b.zip 

UEsDBAoAAAAAAHZki0AAAAAAAAAAAAAAAAAFAAAAYi50eHRQSwECPwAKAAAAAAB2 
ZItAAAAAAAAAAAAAAAAABQAkAAAAAAAAACAAAAAAAAAAYi50eHQKACAAAAAAAAEA 
GAD67/k51xfNAfrv+TnXF80B2tiUMNcXzQFQSwUGAAAAAAEAAQBXAAAAIwAAAAAA 
----boundary_0_1b7bb1ee-ba28-4258-b662-554adb7ff81a-- 

각 첨부 파일의 Content-Type : 및 Content-Disposition : 파일 이름이 일치하지 않는 방식에 유의하십시오.

내가 잘못 했나요? 이 버그는 MS에 로그인해야하는 버그입니까?

답변

3

각 첨부 파일에 대해 ContentType의 새 인스턴스가 필요하기 때문입니다.

var zipCt = new ContentType { MediaType = MediaTypeNames.Application.Zip }; 
var zipCt2 = new ContentType { MediaType = MediaTypeNames.Application.Zip }; 

var attachmentA = new Attachment(@"c:\tmp\emailin\a.zip", zipCt); 
attachmentA.ContentDisposition.FileName = "a.zip"; 
attachmentA.Name = "a.zip"; 

var attachmentB = new Attachment(@"c:\tmp\emailin\b.zip", zipCt2); 
attachmentB.ContentDisposition.FileName = "b.zip"; 
attachmentB.Name = "b.zip"; 

문제를 해결해야합니다.

+0

감사합니다. 이로 인해 문제가 해결되었습니다. 멍청한 실수! – Martyn

관련 문제