Send inline image in email

前端 未结 12 2189
夕颜
夕颜 2020-11-22 11:09

Having an issue sending an image via email as an embedded image in the body. The image file shows as an attachment which is ok but the inline image portion just shows as a r

12条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 11:57

    Try this

     string htmlBody = "

    Picture


    "; AlternateView avHtml = AlternateView.CreateAlternateViewFromString (htmlBody, null, MediaTypeNames.Text.Html); LinkedResource inline = new LinkedResource("filename.jpg", MediaTypeNames.Image.Jpeg); inline.ContentId = Guid.NewGuid().ToString(); avHtml.LinkedResources.Add(inline); MailMessage mail = new MailMessage(); mail.AlternateViews.Add(avHtml); Attachment att = new Attachment(filePath); att.ContentDisposition.Inline = true; mail.From = from_email; mail.To.Add(data.email); mail.Subject = "Client: " + data.client_id + " Has Sent You A Screenshot"; mail.Body = String.Format( "

    Client: " + data.client_id + " Has Sent You A Screenshot

    " + @"", att.ContentId); mail.IsBodyHtml = true; mail.Attachments.Add(att);

提交回复
热议问题