1

Is there a way to set the ContentDisposition of a LinkedResource to be inline, ie in the case of an image?

Here's how I am building my LinkedResource right now:

            Dim img As LinkedResource = New LinkedResource(filePath)

            Dim fileType As String = ""
            Dim attName As String = "image" + fileName + "." + fileExt

            If (fileExt = "jpg" Or fileExt = "jpeg") Then
                img.ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg
            ElseIf (fileExt = "gif") Then
                img.ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Gif
            ElseIf (fileExt = "png") Then
                img.ContentType.MediaType = "image/png"
            End If

            img.ContentId = attName
            img.ContentType.Name = attName
            linkedResources.Add(img)
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126

3 Answers3

1

Adapt the code succinctly described in this answer: https://stackoverflow.com/a/11000938

This appears to be the right approach. Articles describing this in more detail include these:

Community
  • 1
  • 1
trebormf
  • 3,156
  • 3
  • 25
  • 21
0

LinkedResources already sets the ContentDisposition to inline.

In fact, LinkedResources appears to exist only for the purpose of adding hidden embedded images and other inline content to your AlternateView. There is no option to set a filename, since users will never see it.

Use Attachments when you want visible, user-accessible files attached to your email, with filenames.

Use LinkedResources when you want hidden resources such as embedded images in your email, which you then reference in HTML with cid:.

Memetican
  • 381
  • 5
  • 18
  • 2
    I'm not seeing the ContentDisposition being set when I use LinkedResources. – Simon Parker Aug 01 '18 at 03:43
  • Exactly as @SimonParker stated. – Yoda Dec 01 '21 at 12:58
  • Unfortunately it's been some years and several .NET versions since I've worked with System.Mail- it's possible they've changed something here- but it seems unlikely. LinkedResources and Attachments are still separate mechanisms. I'd recommend digging into the docs and experimenting with different calls. https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.linkedresource?view=net-6.0 – Memetican Dec 08 '21 at 08:19
  • Also check the actual email content you're generating- mail readers vary widely in how they render embedded content, and some will show them as attachments. – Memetican Dec 08 '21 at 08:20
0

Adding a "ContentType.Name" value will make it an attachment.

T Brown
  • 1,385
  • 13
  • 9