2012-01-24 8 views
1

EWS를 사용하여 인라인 첨부 파일이있는 이메일을 보내고 있습니다.ew로 인라인 첨부 파일 보내기

나는 그것을 사용하는 다음 코드 해요 : 메시지의

var attachment = attachments.AddFileAttachment(path); 
attachment.ContentId = cid; 
attachment.IsInline = true; 
attachment.ContentType = "PNG/Image"; 

HTML 본문은 조각에게 다음과 같은 포함 {CID}이 CID 필드의 값입니다

<img src=""cid:{cid}""></img> 

.

Outlook에서 이메일을 확인할 때 작동하지만 메시지 본문에 OWA 이미지가 표시되지 않습니다.

OWA에서 볼 수 있도록 EWS를 통해 인라인 이미지가있는 메일을 보내주십시오.

+0

안녕하세요, 해결책을 찾았습니까? –

답변

1

아래 코드는 저에게 효과적이며 Outlook/OWA/Mobile에서 인라인 첨부 파일을 볼 수 있습니다.

단계 : contentids

  • 에 대한 자리와

    1. HTML 본문 실제 첨부 contentids

    2. 에 자리가 새 첨부 파일을 만들고 인라인 (참)의 속성을 설정하는 것이 교체하고 contentid (연결된 첨부 파일의 실제 contentid)

      string attachment = "c:\\inlineattachment.png"; 
      
          // Create an e-mail message using the ExchangeService. 
          EmailMessage message = new EmailMessage(ExchangeServiceObject); 
      
          // Subject 
          message.Subject = "Email with inline attachments"; 
      
          // Message body with place holder for contentid 
          message.Body = "Email body with inline attachment </br> <img src=\"cid:{0}\">"; 
          message.Body.BodyType = BodyType.HTML; 
      
          // Replace the place holder with contentid 
          // Random GUID is used to avoid name collision for contentids 
          string newGuid = Guid.NewGuid().ToString(); 
          message.Body = string.Format(message.Body, newGuid); 
      
          // Create a new attachment and add necessary properties to make it inline 
          message.Attachments.AddFileAttachment(attachment); 
          message.Attachments[message.Attachments.Count - 1].IsInline = true; 
          message.Attachments[message.Attachments.Count - 1].ContentId = newGuid; 
      
          // Add recipeint 
          message.ToRecipients.Add("[email protected]"); 
      
          // Send the e-mail message and save a copy. 
          message.SendAndSaveCopy(); 
      
  • 관련 문제