2012-10-08 14 views
5

Bir html gövdesi olan bir System.Net.Mail iletisi oluşturuyorum. Müşterinin imzasının e-postaya bir jpeg görüntüsü (bayt arayışı) ekleyip servis merkezine gönderiyorum. Servis merkezi eki açmak zorunda kalmadan imzayı görmek istedi, böylece html'yi değiştirdim ve görüntüyü bir LinkedResource olarak tekrar ekledim. Sorun şu ki, ek daha önce olduğundan daha büyük ve eki görüntülemeye çalışırken bir hata görüntüler. Eki kaydeder ve dosyayı bir hex editöründe açarsam, dosyanın tamamı boştur. Bağlı olan kaynağı ekleyen kodu ekleyebilir ve ek yeniden çalışır. Satır içi resmi ve eki nasıl ekleyebilirim? Bu benim kodudur <p><img src=cid:CustomerSignature /></p>Bir resmi nasıl görüntüleyebilirim ve bir e-postaya ek olarak ekleyebilirim

:

Bu

ben de görüntüye gömmek etikettir Kendi soruları yanıtlayan sevmiyorum

System.IO.MemoryStream ms = new System.IO.MemoryStream(insuranceClaim.Signature, 0, insuranceClaim.Signature.Length); 
ms.Position = 0; 
System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType(); 
contentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg; 
contentType.Name = "signature.jpg"; 
System.Net.Mail.Attachment imageAttachment = new System.Net.Mail.Attachment(ms, contentType); 
System.Net.Mime.ContentDisposition disposition = imageAttachment.ContentDisposition; 
mailMessage.Attachments.Add(imageAttachment); 
System.Net.Mail.LinkedResource signature = new System.Net.Mail.LinkedResource(ms, new System.Net.Mime.ContentType("image/jpeg")); 
signature.ContentId = "CustomerSignature"; 
System.Net.Mail.AlternateView aView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailMessage.Body, new System.Net.Mime.ContentType("text/html")); 
aView.LinkedResources.Add(signature); 
mailMessage.AlternateViews.Add(aView); 

cevap

5

ama başkası aynı hatayı yaparsa ben yaptım, işte çözüm. Görüntü verileriyle yeni bir MemoryStream oluşturdum ve ek ile LinkedResource arasındaki akışı paylaşmaya çalıştım. Bir kez 2 MemoryStreams ürettim çalıştı.

System.IO.MemoryStream ms = new System.IO.MemoryStream(insuranceClaim.Signature, 0, insuranceClaim.Signature.Length); 
System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType(); 
contentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg; 
contentType.Name = "signature.jpg"; 
System.Net.Mail.Attachment imageAttachment = new System.Net.Mail.Attachment(ms, contentType); 
mailMessage.Attachments.Add(imageAttachment); 

System.IO.MemoryStream embeddedMs = new System.IO.MemoryStream(insuranceClaim.Signature, 0, insuranceClaim.Signature.Length); 
System.Net.Mail.LinkedResource signature = new System.Net.Mail.LinkedResource(embeddedMs, new System.Net.Mime.ContentType("image/jpeg")); 
signature.ContentId = "CustomerSignature"; 
System.Net.Mail.AlternateView aView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailMessage.Body, new System.Net.Mime.ContentType("text/html")); 
aView.LinkedResources.Add(signature); 
mailMessage.AlternateViews.Add(aView); 
+0

Sorunum farklı: Resmimi Byte dizisine dönüştürmüyordum. Gönderin bana yine de yardım etti;) –

0

Görüntünün içerik türü olarak jpeg/image kullanılması işe yaramaz. Resmi e-postaya yerleştirmeye ve onu base64'e dönüştürmeye çalışır. Ardından gönderen, alıcı ve konu boşaltılır. E-postayı gönderir, ancak tüm bilgiler bozuktur.

İlgili konular