Click here to Skip to main content
14,574,744 members
Rate this:
Please Sign up or sign in to vote.
See more:

My application is already sending email with embedded image, but this time the images were all stored in a database.
I can't figure it out on how to read and process the stored image to be part of the email.

Thanks in advance

What I have tried:

below code is for reading image from file path.

using (FileStream fileStream = new FileStream(Server.MapPath("~/" + fname), FileMode.Open, FileAccess.Read))
  content = new byte[fileStream.Length];
  fileStream.Read(content, 0, content.Length);

fileAttach.Content = content;

                CreateAttachmentType attachmentRequest = new CreateAttachmentType();
                attachmentRequest.Attachments = new AttachmentType[1];
                attachmentRequest.Attachments[0] = fileAttach;
                attachmentRequest.Attachments[0].IsInline = true;
                attachmentRequest.Attachments[0].ContentId = FileName;
                attachmentRequest.ParentItemId = emailResponseMessage.Items.Items[0].ItemId;
Updated 14-Feb-19 12:19pm
Richard MacCutchan 14-Feb-19 4:01am
The same as above, read the image data from the database into the content field.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100