Hey Pls correct this code below as you can
Public Sub ConvertImagesToEmbeddedMailImages(ByVal html As String, ByRef emailMessage As CDO.Message)
Dim document As HtmlDocument = HtmlDocument.Create(html, False)Dim imageNodes As New HtmlNodeCollection()
' Get All the img nodes
GetImageNodes(document.Nodes, imageNodes)
For Each element As HtmlElement In imageNodes
Dim path As String = HttpContext.Current.Server.MapPath(element.Attributes("src").Value)Dim imageFileInfo As New FileInfo(HttpContext.Current.Server.MapPath(element.Attributes("src").Value))
Dim contentId As String = imageFileInfo.Name.Replace(imageFileInfo.Extension, String.Empty)Dim bodyPart As CDO.IBodyPart = emailMessage.AddRelatedBodyPart(path, contentId, CDO.CdoReferenceType.cdoRefTypeLocation, String.Empty, String.Empty)bodyPart.Fields.Append("urn:schemas:mailheader:Content-ID", DataTypeEnum.adVariant, 255, FieldAttributeEnum.adFldMayBeNull, String.Format("<{0}>", contentId))
bodyPart.Fields.Update()
'Change the src to "cid:<contentId>" element.Attributes("src").Value = String.Format("cid:{0}", contentId)
Next
' set the email text to the modified html
emailMessage.HTMLBody = document.HTML
End SubPrivate Sub GetImageNodes(ByVal nodes As HtmlNodeCollection, ByRef imageNodes As MIL.Html.HtmlNodeCollection)
For Each node As HtmlNode In nodesDim element As HtmlElement = TryCast(node, HtmlElement)
If element IsNot Nothing Then
If element.Name.ToLower() = "img" Then
imageNodes.Add(element)
End If
If element.Nodes.Count > 0 Then
GetImageNodes(element.Nodes, imageNodes)
End If
End If
Next
End Sub
I need in urgent na.
regard from
spider anatha
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).