How to imbed an image anywhere in the email body, not just at the top of the body

I am trying to imbed an image in an email. I want the image to show up in the middle of the email body. The code below should imbed the image in the middle of the email body. I append a header first (strFile), followed by some datagrids. After the datagrids I want the image. After the image I append a footer (strFile2). But when I send this email, the image still shows up at the top of the email body, instead of after the datagrids.
Protected Sub btnSendSS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendSS.Click
 
 
            Dim SqlUsage As String
            Dim vEstimatedVol As Integer
            Dim vProspectID As String
            Dim SqlProspect2, SqlProspect3 As String
            Dim vProspectName As String
            Dim vEsiidCount As Integer
            strFile = "No Prospect provided"
            Dim msgAttach1 As String = ""
 
            If chkpdf.Checked = True Then
                'attachment as pdf
            Else
                'snapshot in email body
 
            End If
            vProspectID = Request.QueryString("ContractID")
            If Len(vProspectID) > 0 Then
 
                Dim SRConnProspect As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ToString)
                If SRConnProspect.State <> ConnectionState.Open Then
                    SRConnProspect.Open()
                End If
 
                SqlUsage = "SELECT DISTINCT SUM(MwhAct) * 1000 AS TotalAnnual_Kwh FROM Prospect_Cogs WHERE (Fwd_Mth BETWEEN 1 AND 12) and [ProspectID] = " & vProspectID
                Dim Prospect_Cmd1 As New System.Data.SqlClient.SqlCommand(SqlUsage, SRConnProspect)
                vEstimatedVol = Prospect_Cmd1.ExecuteScalar()
 
 
               
                SqlProspect2 = "select Prospect from tbl_prospect where prospectID = " + vProspectID
                Dim Prospect_Cmd2 As New System.Data.SqlClient.SqlCommand(SqlProspect2, SRConnProspect)
                vProspectName = Prospect_Cmd2.ExecuteScalar()
 
                
                SqlProspect3 = " SELECT COUNT(ESIID) FROM tbl_Esiid WHERE ProspectID = " + vProspectID
                Dim Prospect_Cmd3 As New System.Data.SqlClient.SqlCommand(SqlProspect3, SRConnProspect)
                vEsiidCount = Prospect_Cmd3.ExecuteScalar()
 
                Dim vSourcePath As String
                Dim vSource As String
                Dim fso1, objFile, fso2, objFile2
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmailHeader.html"
 
                fso1 = CreateObject("Scripting.FileSystemObject")
                objFile = fso1.OpenTextFile(vSource)
                strFile = objFile.ReadAll
 
                strFile = Replace(strFile, "<clientname1 />", vProspectName, 1, 1, CompareMethod.Text)
                strFile = Replace(strFile, "<date1 />", Left(Today(), 10).ToString)
                strFile = Replace(strFile, "<totalkwh1 />", FormatNumber(vEstimatedVol, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile = Replace(strFile, "<esiidcount />", vEsiidCount)
               
                objFile.Close()
                objFile = Nothing
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmail.html"
 
                fso2 = CreateObject("Scripting.FileSystemObject")
                objFile2 = fso2.OpenTextFile(vSource)
                strFile2 = objFile2.ReadAll
 
               
                strFile2 = Replace(strFile2, "<a10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
 
                objFile2.Close()
                objFile2 = Nothing
 
 
                If SRConnProspect.State <> ConnectionState.Closed Then
                    SRConnProspect.Close()
                End If
 
            End If
 
            Dim message As New System.Net.Mail.MailMessage()
            Dim mBody As New StringBuilder
            Dim client As New System.Net.Mail.SmtpClient
 
            Dim SRConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ConnectionString)
 
            If SRConn.State <> Data.ConnectionState.Open Then
                SRConn.Open()
            End If
 
            Try
                Select Case txtSendEmailAddress.Text.Trim
                    Case ""
                        message.To.Add(New Net.Mail.MailAddress(vEmail))
                    Case Else
                        message.To.Add(New Net.Mail.MailAddress(txtSendEmailAddress.Text.Trim))
                End Select
 
                mBody.Append(strFile)
 
 
                mBody.Append("<table>")
                mBody.Append("<tr>")
                mBody.Append("<td colspan=""6"">")
                mBody.Append("*Indicative pricing")
                mBody.Append("</td>")
                mBody.Append("</tr>")
                mBody.Append("<tr>")
                If pnlFixedSS.Visible = True Then
                    dgFixedSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedWSSS.Visible = True Then
                    dgFixedWSSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedWSSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedPTSS.Visible = True Then
                    dgFixedPTSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedPTSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEBundledSS.Visible = True Then
                    dgMCPEBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEUnbundledSS.Visible = True Then
                    dgMCPEUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlSplitBundledSS.Visible = True Then
                    dgSplitBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlSplitUnbundledSS.Visible = True Then
                    dgSplitUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitUnbundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffBundledSS.Visible = True Then
                    dgOnOffBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffUnbundledSS.Visible = True Then
                    dgOnOffUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlWSHRBundledSS.Visible = True Then
                    dgWSHRBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlWSHRUnbundledSS.Visible = True Then
                    dgWSHRUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlRetailHRSS.Visible = True Then
                    dgRetailHRSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgRetailHRSS))
                    mBody.Append("</td>")
                End If
 
                mBody.Append("</tr>")
 
                mBody.Append("</table>")
 
                mBody.Append(strFile2)
 
               
 
                message.Subject = "Indicative Pricing Snapshot for " & vProspectName
 
 
                Dim objAVHTML As Net.Mail.AlternateView
                Dim objPicture As Net.Mail.LinkedResource
                objPicture = New Net.Mail.LinkedResource("D:\Inetpub\wwwroot\IEnergy_Dev\images\WF1_Large.jpg")
                objPicture.ContentId = "PictureOfLogo"
 
 
                objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<img src=""cid:PictureOfLogo"">" + mBody.ToString(), Nothing, "text/html")
                objAVHTML.LinkedResources.Add(objPicture)
 
                message.AlternateViews.Add(objAVHTML)
 
 
                message.IsBodyHtml = True
                client.Send(message)
                SaveOffer()
            Catch ex As Exception
            End Try
            If SRConn.State <> Data.ConnectionState.Closed Then
                SRConn.Close()
            End If
        End Sub

Open in new window

LVL 3
utlonghornjulieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cdaly33Commented:
how about adding the image as another row in your table before closing the table.
Protected Sub btnSendSS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendSS.Click
 
 
            Dim SqlUsage As String
            Dim vEstimatedVol As Integer
            Dim vProspectID As String
            Dim SqlProspect2, SqlProspect3 As String
            Dim vProspectName As String
            Dim vEsiidCount As Integer
            strFile = "No Prospect provided"
            Dim msgAttach1 As String = ""
 
            If chkpdf.Checked = True Then
                'attachment as pdf
            Else
                'snapshot in email body
 
            End If
            vProspectID = Request.QueryString("ContractID")
            If Len(vProspectID) > 0 Then
 
                Dim SRConnProspect As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ToString)
                If SRConnProspect.State <> ConnectionState.Open Then
                    SRConnProspect.Open()
                End If
 
                SqlUsage = "SELECT DISTINCT SUM(MwhAct) * 1000 AS TotalAnnual_Kwh FROM Prospect_Cogs WHERE (Fwd_Mth BETWEEN 1 AND 12) and [ProspectID] = " & vProspectID
                Dim Prospect_Cmd1 As New System.Data.SqlClient.SqlCommand(SqlUsage, SRConnProspect)
                vEstimatedVol = Prospect_Cmd1.ExecuteScalar()
 
 
               
                SqlProspect2 = "select Prospect from tbl_prospect where prospectID = " + vProspectID
                Dim Prospect_Cmd2 As New System.Data.SqlClient.SqlCommand(SqlProspect2, SRConnProspect)
                vProspectName = Prospect_Cmd2.ExecuteScalar()
 
                
                SqlProspect3 = " SELECT COUNT(ESIID) FROM tbl_Esiid WHERE ProspectID = " + vProspectID
                Dim Prospect_Cmd3 As New System.Data.SqlClient.SqlCommand(SqlProspect3, SRConnProspect)
                vEsiidCount = Prospect_Cmd3.ExecuteScalar()
 
                Dim vSourcePath As String
                Dim vSource As String
                Dim fso1, objFile, fso2, objFile2
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmailHeader.html"
 
                fso1 = CreateObject("Scripting.FileSystemObject")
                objFile = fso1.OpenTextFile(vSource)
                strFile = objFile.ReadAll
 
                strFile = Replace(strFile, "<clientname1 />", vProspectName, 1, 1, CompareMethod.Text)
                strFile = Replace(strFile, "<date1 />", Left(Today(), 10).ToString)
                strFile = Replace(strFile, "<totalkwh1 />", FormatNumber(vEstimatedVol, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile = Replace(strFile, "<esiidcount />", vEsiidCount)
               
                objFile.Close()
                objFile = Nothing
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmail.html"
 
                fso2 = CreateObject("Scripting.FileSystemObject")
                objFile2 = fso2.OpenTextFile(vSource)
                strFile2 = objFile2.ReadAll
 
               
                strFile2 = Replace(strFile2, "<a10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
 
                objFile2.Close()
                objFile2 = Nothing
 
 
                If SRConnProspect.State <> ConnectionState.Closed Then
                    SRConnProspect.Close()
                End If
 
            End If
 
            Dim message As New System.Net.Mail.MailMessage()
            Dim mBody As New StringBuilder
            Dim client As New System.Net.Mail.SmtpClient
 
            Dim SRConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ConnectionString)
 
            If SRConn.State <> Data.ConnectionState.Open Then
                SRConn.Open()
            End If
 
            Try
                Select Case txtSendEmailAddress.Text.Trim
                    Case ""
                        message.To.Add(New Net.Mail.MailAddress(vEmail))
                    Case Else
                        message.To.Add(New Net.Mail.MailAddress(txtSendEmailAddress.Text.Trim))
                End Select
 
                mBody.Append(strFile)
 
 
                mBody.Append("<table>")
                mBody.Append("<tr>")
                mBody.Append("<td colspan=""6"">")
                mBody.Append("*Indicative pricing")
                mBody.Append("</td>")
                mBody.Append("</tr>")
                mBody.Append("<tr>")
                If pnlFixedSS.Visible = True Then
                    dgFixedSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedWSSS.Visible = True Then
                    dgFixedWSSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedWSSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedPTSS.Visible = True Then
                    dgFixedPTSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedPTSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEBundledSS.Visible = True Then
                    dgMCPEBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEUnbundledSS.Visible = True Then
                    dgMCPEUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlSplitBundledSS.Visible = True Then
                    dgSplitBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlSplitUnbundledSS.Visible = True Then
                    dgSplitUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitUnbundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffBundledSS.Visible = True Then
                    dgOnOffBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffUnbundledSS.Visible = True Then
                    dgOnOffUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlWSHRBundledSS.Visible = True Then
                    dgWSHRBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlWSHRUnbundledSS.Visible = True Then
                    dgWSHRUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlRetailHRSS.Visible = True Then
                    dgRetailHRSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgRetailHRSS))
                    mBody.Append("</td>")
                End If
 
                mBody.Append("</tr>")
  
                mBody.Append(strFile2)
 
               
 
                message.Subject = "Indicative Pricing Snapshot for " & vProspectName
 
 
                Dim objAVHTML As Net.Mail.AlternateView
                Dim objPicture As Net.Mail.LinkedResource
                objPicture = New Net.Mail.LinkedResource("D:\Inetpub\wwwroot\IEnergy_Dev\images\WF1_Large.jpg")
                objPicture.ContentId = "PictureOfLogo"
 
 
                objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<tr><img src=""cid:PictureOfLogo""></tr>" + mBody.ToString(), Nothing, "text/html")
                objAVHTML.LinkedResources.Add(objPicture)
 
                message.AlternateViews.Add(objAVHTML)
 
				
				
                mBody.Append("</table>")
 
 
                message.IsBodyHtml = True
                client.Send(message)
                SaveOffer()
            Catch ex As Exception
            End Try
            If SRConn.State <> Data.ConnectionState.Closed Then
                SRConn.Close()
            End If
        End Sub

Open in new window

0
cdaly33Commented:
Sorry, one edit on that previous code.  In the text declaration of the CreateAlternateViewFromString you need to add cell tags.
"<tr><td><img src=""cid:PictureOfLogo""></td></tr>"
0
TADemetCommented:
The image is showing up at the top of the e-mail because that is where you are putting it.  I agree with cdaly33 that you need to put in the html content referencing the cid.

I created a class to do this. Below is the code.  The code take the entire html body of the e-mail including the images and replaces the image with the cid.
Imports Microsoft.VisualBasic
Imports System.Web.Hosting
Imports System.Net.Mail
Imports System.Text.RegularExpressions
Imports System.IO
 
 
 
Namespace Helpers
	Public Class MailHelper
 
		Private _htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(String.Empty)
 
		''' <summary>
		''' Send e-mail
		''' </summary>
		''' <param name="strHTMLBody"></param>
		''' <param name="strTXTBody"></param>
		''' <param name="strSubject"></param>
		''' <param name="strToAddress"></param>
		''' <param name="strToName"></param>
		''' <param name="strFromAddress"></param>
		''' <param name="strFromName"></param>
		''' <returns>Boolean</returns>
		''' <remarks></remarks>
		Public Function SendMail(ByVal strHTMLBody As String, ByVal strTXTBody As String, ByVal strSubject As String, ByVal strToAddress As String, ByVal strToName As String, ByVal strFromAddress As String, ByVal strFromName As String) As Boolean
			Dim Message As New MailMessage
			Dim blnSuccess As Boolean = False
 
			Message.Subject = strSubject
 
			If String.IsNullOrEmpty(strToAddress) Or String.IsNullOrEmpty(strFromAddress) Then Exit Function
 
			If Not String.IsNullOrEmpty(strToName) Then
				Message.To.Add(New MailAddress(strToAddress, strToName))
			Else
				Message.To.Add(New MailAddress(strToAddress))
			End If
 
			If Not String.IsNullOrEmpty(strFromName) Then
				Message.From = New MailAddress(strFromAddress, strFromName)
			Else
				Message.From = New MailAddress(strFromAddress)
			End If
 
 
			If Not String.IsNullOrEmpty(strHTMLBody) Then
				Message.AlternateViews.Add(GetHTMLView(strHTMLBody))
			End If
 
			If Not String.IsNullOrEmpty(strTXTBody) Then
				Message.AlternateViews.Add(GetPlainView(strTXTBody))
			End If
			Dim SMTP As New SmtpClient
			Try
				SMTP.Send(Message)
				Return True
			Catch ex As Exception
				Return False
			End Try
		End Function
 
		Private Function GetPlainView(ByVal strTextBody As String) As AlternateView
			Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(strTextBody, Nothing, "text/plain")
			Return plainView
		End Function
 
		''' <summary>
		''' Gets an HTML alternate view for the mailmessage
		''' </summary>
		''' <param name="strHTMLBody"></param>
		''' <returns>AlternateView</returns>
		''' <remarks></remarks>
		Private Function GetHTMLView(ByVal strHTMLBody As String) As AlternateView
 
			Dim I As Integer = 0
			Dim sb As New StringBuilder
			Dim ResultString As String
			Dim myMatchEvaluator As MatchEvaluator = New MatchEvaluator(AddressOf ComputeReplacement)
 
			Using sr As New StringReader(strHTMLBody)
				Dim input As String
				input = sr.ReadLine
				While Not input Is Nothing
					Try
						ResultString = Regex.Replace(input, "src[^>]*[^/].(?:jpg|bmp|gif)(?:\""|\')", myMatchEvaluator, RegexOptions.IgnoreCase)
						sb.AppendLine(ResultString)
					Catch ex As ArgumentException
						sb.AppendLine(input)
					End Try
					input = sr.ReadLine
				End While
			End Using
 
			Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(sb.ToString, Nothing, "text/html")
			For D As Integer = 0 To _htmlView.LinkedResources.Count - 1
				htmlView.LinkedResources.Add(_htmlView.LinkedResources.Item(D))
			Next
			Return htmlView
		End Function
 
		Public Function ComputeReplacement(ByVal m As Match) As String
			'You can vary the replacement text for each match on-the-fly
			Static Dim I As Integer
			Dim strPath As String = String.Empty
			Try
				Dim strImages(m.Captures.Count, 2) As String
				strPath = m.Captures(0).Value.Substring(5, m.Captures(0).Value.Length - 6)
				Dim image As New LinkedResource(System.Web.Hosting.HostingEnvironment.MapPath("~" & strPath))
				image.ContentId = "image_" & I
				I = I + 1
				_htmlView.LinkedResources.Add(image)
				Return "src=""cid:image_" & I - 1 & """"
			Catch ex As Exception
				Return m.Value.ToString
			End Try
			
 
		End Function
	End Class
End Namespace

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

utlonghornjulieAuthor Commented:
If I use the class, how would I call it in my code?
0
utlonghornjulieAuthor Commented:
I tried it by appending the image within another row in the table, but it did not work. The image does not show up in the email. Instead, the words "System.Net.Mail.AlternateView" show up where the image should be.
Protected Sub btnSendSS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendSS.Click
 
 
            Dim SqlUsage As String
            Dim vEstimatedVol As Integer
            Dim vProspectID As String
            Dim SqlProspect2, SqlProspect3 As String
            Dim vProspectName As String
            Dim vEsiidCount As Integer
            strFile = "No Prospect provided"
            Dim msgAttach1 As String = ""
 
            If chkpdf.Checked = True Then
                'attachment as pdf
            Else
                'snapshot in email body
 
            End If
            vProspectID = Request.QueryString("ContractID")
            If Len(vProspectID) > 0 Then
 
                Dim SRConnProspect As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ToString)
                If SRConnProspect.State <> ConnectionState.Open Then
                    SRConnProspect.Open()
                End If
 
                SqlUsage = "SELECT DISTINCT SUM(MwhAct) * 1000 AS TotalAnnual_Kwh FROM Prospect_Cogs WHERE (Fwd_Mth BETWEEN 1 AND 12) and [ProspectID] = " & vProspectID
                Dim Prospect_Cmd1 As New System.Data.SqlClient.SqlCommand(SqlUsage, SRConnProspect)
                vEstimatedVol = Prospect_Cmd1.ExecuteScalar()
 
 
               
                SqlProspect2 = "select Prospect from tbl_prospect where prospectID = " + vProspectID
                Dim Prospect_Cmd2 As New System.Data.SqlClient.SqlCommand(SqlProspect2, SRConnProspect)
                vProspectName = Prospect_Cmd2.ExecuteScalar()
 
                
                SqlProspect3 = " SELECT COUNT(ESIID) FROM tbl_Esiid WHERE ProspectID = " + vProspectID
                Dim Prospect_Cmd3 As New System.Data.SqlClient.SqlCommand(SqlProspect3, SRConnProspect)
                vEsiidCount = Prospect_Cmd3.ExecuteScalar()
 
                Dim vSourcePath As String
                Dim vSource As String
                Dim fso1, objFile, fso2, objFile2
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmailHeader.html"
 
                fso1 = CreateObject("Scripting.FileSystemObject")
                objFile = fso1.OpenTextFile(vSource)
                strFile = objFile.ReadAll
 
                strFile = Replace(strFile, "<clientname1 />", vProspectName, 1, 1, CompareMethod.Text)
                strFile = Replace(strFile, "<date1 />", Left(Today(), 10).ToString)
                strFile = Replace(strFile, "<totalkwh1 />", FormatNumber(vEstimatedVol, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile = Replace(strFile, "<esiidcount />", vEsiidCount)
               
                objFile.Close()
                objFile = Nothing
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmail.html"
 
                fso2 = CreateObject("Scripting.FileSystemObject")
                objFile2 = fso2.OpenTextFile(vSource)
                strFile2 = objFile2.ReadAll
 
               
                strFile2 = Replace(strFile2, "<a10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
 
                objFile2.Close()
                objFile2 = Nothing
 
 
                If SRConnProspect.State <> ConnectionState.Closed Then
                    SRConnProspect.Close()
                End If
 
            End If
 
            Dim message As New System.Net.Mail.MailMessage()
            Dim mBody As New StringBuilder
            Dim client As New System.Net.Mail.SmtpClient
 
            Dim SRConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ConnectionString)
 
            If SRConn.State <> Data.ConnectionState.Open Then
                SRConn.Open()
            End If
 
            Try
                Select Case txtSendEmailAddress.Text.Trim
                    Case ""
                        message.To.Add(New Net.Mail.MailAddress(vEmail))
                    Case Else
                        message.To.Add(New Net.Mail.MailAddress(txtSendEmailAddress.Text.Trim))
                End Select
 
                mBody.Append(strFile)
 
 
                mBody.Append("<table>")
 
 
                Dim objAVHTML As Net.Mail.AlternateView
                Dim objPicture As Net.Mail.LinkedResource
                objPicture = New Net.Mail.LinkedResource("D:\Inetpub\wwwroot\IEnergy_Dev\images\WF1_Large.jpg")
                objPicture.ContentId = "PictureOfLogo"
 
                objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<tr><td><img src=""cid:PictureOfLogo""></td></tr>", Nothing, "text/html")
 
                'objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<img src=""cid:PictureOfLogo"">" + mBody.ToString(), Nothing, "text/html")
                objAVHTML.LinkedResources.Add(objPicture)
 
                'message.AlternateViews.Add(objAVHTML)
                mBody.Append(objAVHTML)
 
                mBody.Append("<tr>")
                mBody.Append("<td colspan=""6"">")
                mBody.Append("*Indicative pricing")
                mBody.Append("</td>")
                mBody.Append("</tr>")
                mBody.Append("<tr>")
                If pnlFixedSS.Visible = True Then
                    dgFixedSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedWSSS.Visible = True Then
                    dgFixedWSSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedWSSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedPTSS.Visible = True Then
                    dgFixedPTSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedPTSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEBundledSS.Visible = True Then
                    dgMCPEBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEUnbundledSS.Visible = True Then
                    dgMCPEUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlSplitBundledSS.Visible = True Then
                    dgSplitBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlSplitUnbundledSS.Visible = True Then
                    dgSplitUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitUnbundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffBundledSS.Visible = True Then
                    dgOnOffBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffUnbundledSS.Visible = True Then
                    dgOnOffUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlWSHRBundledSS.Visible = True Then
                    dgWSHRBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlWSHRUnbundledSS.Visible = True Then
                    dgWSHRUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlRetailHRSS.Visible = True Then
                    dgRetailHRSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgRetailHRSS))
                    mBody.Append("</td>")
                End If
 
                mBody.Append("</tr>")
 
                mBody.Append("</table>")
 
                mBody.Append(strFile2)
 
                message.Body = mBody.ToString()
 
                message.Subject = "Indicative Pricing Snapshot for " & vProspectName
 
 
 
 
                message.IsBodyHtml = True
                client.Send(message)
                SaveOffer()
            Catch ex As Exception
            End Try
            If SRConn.State <> Data.ConnectionState.Closed Then
                SRConn.Close()
            End If
        End Sub

Open in new window

0
TADemetCommented:
Use the SendMail function.
SendMail(ByVal strHTMLBody As String, ByVal strTXTBody As String, ByVal strSubject As String, ByVal strToAddress As String, ByVal strToName As String, ByVal strFromAddress As String, ByVal strFromName As String) As Boolean

strHTMLBody is the e-mail body in HTML form strHTMLBody = mBody.tostring
strTXTBody is the e-mail body in Text form
strSubject is the e-mail subject
strToAddress is the address the e-mail is going to. 'jcustomer@msn.com'
strToName is the name to display 'Joe Customer'
strFromAddress is the address the e-mail is coming from 'jdoe@acme.com'
strFromName is the name the e-mail is coming from 'John Doe'

Dim helper as new Helpers.MailHelper
Dim body as String
dim success as Boolean
body = "<html><head><title>Hello World</head><body><img src=""/images/new.jpg"" alt=""Hello Wold"" width=""230px"" height=""150px"" /><h1>Welcome</h1></body></html>"
 
success = helper.SendMail(body, string.empty,"Hello World","jcustomer@msn.com","Joe Customer","jdoe@acme.com","John Doe")

Open in new window

0
utlonghornjulieAuthor Commented:
Ok I added that code, but the email that gets sent still does not show the image. Instead, the words "System.Net.Mail.AlternateView" show up where the image should be.
Protected Sub btnSendSS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendSS.Click
 
 
            Dim SqlUsage As String
            Dim vEstimatedVol As Integer
            Dim vProspectID As String
            Dim SqlProspect2, SqlProspect3 As String
            Dim vProspectName As String
            Dim vEsiidCount As Integer
            strFile = "No Prospect provided"
            Dim msgAttach1 As String = ""
 
            If chkpdf.Checked = True Then
                'attachment as pdf
            Else
                'snapshot in email body
 
            End If
            vProspectID = Request.QueryString("ContractID")
            If Len(vProspectID) > 0 Then
 
                Dim SRConnProspect As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ToString)
                If SRConnProspect.State <> ConnectionState.Open Then
                    SRConnProspect.Open()
                End If
 
                SqlUsage = "SELECT DISTINCT SUM(MwhAct) * 1000 AS TotalAnnual_Kwh FROM Prospect_Cogs WHERE (Fwd_Mth BETWEEN 1 AND 12) and [ProspectID] = " & vProspectID
                Dim Prospect_Cmd1 As New System.Data.SqlClient.SqlCommand(SqlUsage, SRConnProspect)
                vEstimatedVol = Prospect_Cmd1.ExecuteScalar()
 
 
               
                SqlProspect2 = "select Prospect from tbl_prospect where prospectID = " + vProspectID
                Dim Prospect_Cmd2 As New System.Data.SqlClient.SqlCommand(SqlProspect2, SRConnProspect)
                vProspectName = Prospect_Cmd2.ExecuteScalar()
 
                
                SqlProspect3 = " SELECT COUNT(ESIID) FROM tbl_Esiid WHERE ProspectID = " + vProspectID
                Dim Prospect_Cmd3 As New System.Data.SqlClient.SqlCommand(SqlProspect3, SRConnProspect)
                vEsiidCount = Prospect_Cmd3.ExecuteScalar()
 
                Dim vSourcePath As String
                Dim vSource As String
                Dim fso1, objFile, fso2, objFile2
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmailHeader.html"
 
                fso1 = CreateObject("Scripting.FileSystemObject")
                objFile = fso1.OpenTextFile(vSource)
                strFile = objFile.ReadAll
 
                strFile = Replace(strFile, "<clientname1 />", vProspectName, 1, 1, CompareMethod.Text)
                strFile = Replace(strFile, "<date1 />", Left(Today(), 10).ToString)
                strFile = Replace(strFile, "<totalkwh1 />", FormatNumber(vEstimatedVol, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile = Replace(strFile, "<esiidcount />", vEsiidCount)
               
                objFile.Close()
                objFile = Nothing
 
                'Read from Web.Config settings.
                vSourcePath = ConfigurationManager.AppSettings("Templates")
                vSource = vSourcePath & "EnvImpactEmail.html"
 
                fso2 = CreateObject("Scripting.FileSystemObject")
                objFile2 = fso2.OpenTextFile(vSource)
                strFile2 = objFile2.ReadAll
 
               
                strFile2 = Replace(strFile2, "<a10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<a100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0), 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<b100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) * 0.9, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c10 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.1) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c15 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.15) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c35 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.3) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c50 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.5) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c70 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 0.7) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
                strFile2 = Replace(strFile2, "<c100 />", FormatNumber((vEstimatedVol / 1000 * ConfigurationManager.AppSettings("CO2Displacement") * 1.0) / 16.65, 0, TriState.False, TriState.False, TriState.True).ToString)
 
                objFile2.Close()
                objFile2 = Nothing
 
 
                If SRConnProspect.State <> ConnectionState.Closed Then
                    SRConnProspect.Close()
                End If
 
            End If
 
            Dim message As New System.Net.Mail.MailMessage()
            Dim mBody As New StringBuilder
            Dim client As New System.Net.Mail.SmtpClient
 
            Dim SRConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StikeData").ConnectionString)
 
            If SRConn.State <> Data.ConnectionState.Open Then
                SRConn.Open()
            End If
 
            Try
                Select Case txtSendEmailAddress.Text.Trim
                    Case ""
                        message.To.Add(New Net.Mail.MailAddress(vEmail))
                    Case Else
                        message.To.Add(New Net.Mail.MailAddress(txtSendEmailAddress.Text.Trim))
                End Select
 
                mBody.Append(strFile)
 
 
                mBody.Append("<table>")
 
 
                Dim objAVHTML As Net.Mail.AlternateView
                Dim objPicture As Net.Mail.LinkedResource
                objPicture = New Net.Mail.LinkedResource("D:\Inetpub\wwwroot\IEnergy_Dev\images\WF1_Large.jpg")
                objPicture.ContentId = "PictureOfLogo"
 
                objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<tr><td><img src=""cid:PictureOfLogo""></td></tr>", Nothing, "text/html")
 
                'objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<img src=""cid:PictureOfLogo"">" + mBody.ToString(), Nothing, "text/html")
                objAVHTML.LinkedResources.Add(objPicture)
 
                'message.AlternateViews.Add(objAVHTML)
                mBody.Append(objAVHTML)
 
                mBody.Append("<tr>")
                mBody.Append("<td colspan=""6"">")
                mBody.Append("*Indicative pricing")
                mBody.Append("</td>")
                mBody.Append("</tr>")
                mBody.Append("<tr>")
                If pnlFixedSS.Visible = True Then
                    dgFixedSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedWSSS.Visible = True Then
                    dgFixedWSSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedWSSS))
                    mBody.Append("</td>")
                End If
                If pnlFixedPTSS.Visible = True Then
                    dgFixedPTSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(dgFixedPTSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEBundledSS.Visible = True Then
                    dgMCPEBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlMCPEUnbundledSS.Visible = True Then
                    dgMCPEUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgMCPEUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlSplitBundledSS.Visible = True Then
                    dgSplitBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlSplitUnbundledSS.Visible = True Then
                    dgSplitUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgSplitUnbundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffBundledSS.Visible = True Then
                    dgOnOffBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlOnOffUnbundledSS.Visible = True Then
                    dgOnOffUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgOnOffUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlWSHRBundledSS.Visible = True Then
                    dgWSHRBundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRBundledSS))
                    mBody.Append("</td>")
                End If
                If Me.pnlWSHRUnbundledSS.Visible = True Then
                    dgWSHRUnbundledSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgWSHRUnbundledSS))
                    mBody.Append("</td>")
                End If
 
                If Me.pnlRetailHRSS.Visible = True Then
                    dgRetailHRSS.HeaderStyle.BackColor = Drawing.Color.Green
                    mBody.Append("<td>")
                    mBody.Append(getHTML(Me.dgRetailHRSS))
                    mBody.Append("</td>")
                End If
 
                mBody.Append("</tr>")
 
                mBody.Append("</table>")
 
                mBody.Append(strFile2)
 
                message.Body = mBody.ToString()
 
                message.Subject = "Indicative Pricing Snapshot for " & vProspectName
 
                Dim helper As New Helpers.MailHelper
 
                Dim body As String
                Dim success As Boolean
                body = "<html><head><title>Hello World</head><body><img src=""/images/new.jpg"" alt=""Hello Wold"" width=""230px"" height=""150px"" /><h1>Welcome</h1></body></html>"
 
                success = helper.SendMail(mBody.ToString(), String.Empty, "Indicative Pricing Snapshot for " & vProspectName, "julie.liu@greenmountain.com", "Julie", "PricingDesk@greenmountain.com", "Pricing Desk")
 
 
 
                'message.IsBodyHtml = True
                'client.Send(message)
                SaveOffer()
            Catch ex As Exception
            End Try
            If SRConn.State <> Data.ConnectionState.Closed Then
                SRConn.Close()
            End If
        End Sub

Open in new window

0
TADemetCommented:
Comment out this code
Dim objPicture As Net.Mail.LinkedResource
                objPicture = New Net.Mail.LinkedResource("D:\Inetpub\wwwroot\IEnergy_Dev\images\WF1_Large.jpg")
                objPicture.ContentId = "PictureOfLogo"
 
                objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<tr><td><img src=""cid:PictureOfLogo""></td></tr>", Nothing, "text/html")
 
                'objAVHTML = Net.Mail.AlternateView.CreateAlternateViewFromString("<img src=""cid:PictureOfLogo"">" + mBody.ToString(), Nothing, "text/html")
                objAVHTML.LinkedResources.Add(objPicture)

Just use mbody.AppendLine("<tr><td><img src=""/images/WF1_Large.jpg"" /></td></tr>")

The class is going to handle the alternate view and sending the e-mail.
0
utlonghornjulieAuthor Commented:
Thank you that worked great!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.