Question Sending an e-mail with images as linked resources

bifteki

New member
Joined
Jul 24, 2009
Messages
4
Programming Experience
Beginner
I am trying to send an e-mail via a CLR stored procedure in VB.NET.
I have managed to send the HTML body, however I have had trouble with the embedded images.
The images are stored in the SQL Server as nvarchar in an ASCII format. I stored them through code in the DB in the base MS Access application (it's the one that calls the CLR procedure). The format of the field is as follows: "255;216;255;224;0;..." (just an example of what the text in the field might begin like).

The embedding of the images is supposed to be done through the following code:

Dim SQLcmd As New SqlCommand
Dim SQLConn As New SqlConnection("context connection=true")
Dim RD As SqlDataReader
Dim tmpImage As String
Dim imagesArray() As LinkedResource
Dim k As Integer
Dim l As Integer
Dim countImages As Integer

SQLcmd.CommandText = "SELECT dbo.tbl_email_resources.fld_image, dbo.tbl_email_resources.fld_cid, dbo.tbl_sent_history.fld_content_id " & _
"FROM dbo.tbl_sent_history INNER JOIN " & _
"dbo.tbl_email_content ON dbo.tbl_sent_history.fld_content_id = dbo.tbl_email_content.fld_content_id INNER JOIN " & _
"dbo.tbl_email_resources ON dbo.tbl_email_content.fld_content_id = dbo.tbl_email_resources.fld_content_id " & _
"WHERE(dbo.tbl_sent_history.fld_content_id = " & CInt(contID) & ")"

SQLcmd.CommandType = CommandType.Text
SQLcmd.Connection = SQLConn

SQLConn.Open()

RD = SQLcmd.ExecuteReader()

k = 0
ReDim imagesArray(0)

While RD.Read()
ReDim Preserve imagesArray(k)
tmpImage = RD(0).ToString
tmpImage = Replace(tmpImage, ";", " ")
imagesArray(k) = LinkedResource.CreateLinkedResourceFromString(tmpImage, New System.Text.ASCIIEncoding, "image/jpg")
imagesArray(k).ContentId = RD(1).ToString
k = k + 1
End While

countImages = k - 1

SQLConn.Close()


However, what I get when I send the e-mail is the HTML body and a number of .dat files as attachments (the same number as the images), which contains (when opened with notepad) the above mentioned content of the field ("255;216;255;224;0;...etc" for the example I mentioned).

I am sure I have got something wrong about the use of the CreateLinkedResourceFromString method, as the information I found on the internet was almost inexistent. Can anyone shed any light on this please?

PS: Btw, I even tried it without the " tmpImage = Replace(tmpImage, ";", " ")" line.
 
Back
Top