Here is a function that will fix the problem. Call it before you SendEmail like:
ProcessEmbeddingImages(mailMessage);
return MailService.SendEmail(mailMessage);
The ProcessEmbeddingImages function is written in VB.Net so you might want to translate it to c# using one of those online translators.
Private Sub ProcessEmbeddingImages(ByRef oMail As System.Net.Mail.MailMessage)
Dim oLinkedResources As New Hashtable()
oMail.Body = PadSrcDataImage(oMail.Body, oLinkedResources)
If oLinkedResources.Count > 0 Then
Dim oAlternateView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(oMail.Body, Nothing, "text/html")
oAlternateView.ContentId = "htmlView"
oAlternateView.TransferEncoding = Net.Mime.TransferEncoding.SevenBit
For Each oItem As DictionaryEntry In oLinkedResources
Dim oKey As String() = Split(oItem.Key, "-")
Dim i As Integer = oKey(0)
Dim sExt As String = oKey(1)
Dim sData As String = oItem.Value
Dim oLinkedResource As New System.Net.Mail.LinkedResource(New IO.MemoryStream(System.Convert.FromBase64String(sData)))
oLinkedResource.ContentId = "MyImg" & i
oLinkedResource.TransferEncoding = Net.Mime.TransferEncoding.Base64
oLinkedResource.ContentType = New System.Net.Mime.ContentType("image/" & sExt)
oAlternateView.LinkedResources.Add(oLinkedResource)
Next
oMail.AlternateViews.Add(oAlternateView)
End If
End Sub
Private Function PadSrcDataImage(ByVal sHtml As String, ByRef oLinkedResources As Hashtable) As String
Dim oList As New ArrayList
Dim sSearch As String = "\ssrc=['""]data:image/(.*?);base64,(.*?)['""]"
Dim oMatches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(sHtml, sSearch, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
For Each m As System.Text.RegularExpressions.Match In oMatches
If m.Groups.Count >= 2 Then
Dim sExt As String = m.Groups(1).Value
Dim sData As String = m.Groups(2).Value
If sData.Length > 7 AndAlso Right(sData, 6) = "%3D%3D" Then
'Replace trailing %3D%3D with ==
sData = Left(sData, sData.Length - 6) & "=="
End If
oLinkedResources.Add(oLinkedResources.Count & "-" & sExt, sData)
Dim iPos1 As Integer = m.Groups(1).Index - "data:image/".Length
Dim iPos2 As Integer = m.Groups(2).Index + m.Groups(2).Length
Dim iPoints As Integer() = {iPos1, iPos2}
oList.Add(iPoints)
End If
Next
Dim sRet As String = ""
If oList.Count = 1 Then 'One img
Dim iPoints As Integer() = oList(0)
Dim sStr1 As String = sHtml.Substring(0, iPoints(0))
Dim sStr2 As String = sHtml.Substring(iPoints(1))
sRet = sStr1 & "cid:MyImg0" & sStr2
ElseIf oList.Count > 1 Then
For i As Integer = 0 To oList.Count - 1
Dim iPoints As Integer() = oList(i)
Dim iPos1 As Integer = iPoints(0)
If i = 0 Then
'First img
Dim sStr1 As String = sHtml.Substring(0, iPos1)
sRet += sStr1 & "cid:MyImg" & i
Else 'Rest imgs
Dim iPrevPos2 As Integer = oList(i - 1)(1)
Dim sStr1 As String = sHtml.Substring(iPrevPos2, iPos1 - iPrevPos2)
sRet += sStr1 & "cid:MyImg" & i
If i = oList.Count - 1 Then 'Last
sRet += sHtml.Substring(iPoints(1))
End If
End If
Next
End If
If sRet <> "" Then
Return sRet
Else
Return sHtml
End If
End Function