将图像嵌入电子邮件正文问题

编程入门 行业动态 更新时间:2024-10-28 02:27:30
本文介绍了将图像嵌入电子邮件正文问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Dim mMailmessage As New MailMessage Dim mSmtpClient As New SmtpClient("......") mSmtpClient.EnableSsl = True Dim body1 As String = "" body1 += "<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td style='border-bottom-color:#333; border-bottom-width:1px; border-bottom-style:solid;'><img src='eyemails/mail/logo.jpg' width='150' height='41' /></td><td valign='bottom' style='border-bottom-color:#333;border-bottom-width:1px; border-bottom-style:solid;'><table border='0' align='right' cellpadding='0' cellspacing='2'><tr valign='top'><td align='right'><span style='font-size:11px; font-family:Arial;'> Keep In Touch  </span></td><td align='right'><img src='eyemails/mail/fb.gif' width='16' height='16'></td><td align='right' style='font-size:11px; font-family:Arial;color:#C00000; padding-removed4px;'>eyemails</td><td align='right'><img src='eyemails/mail/twit.gif' width='16' height='16'></td><td align='right' style='font-size:11px; font-family:Arial;color:#C00000; padding-removed4px;'>@eyemails</td><td align='right'><img src='eyemails/mail/in.jpg' width='16' height='16'></td><td align='right' style='font-size:11px; font-family:Arial;color:#C00000;'>eyemails</td></tr></table></td></tr></table><table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td height='50'> </td></tr><tr><td style='font-family:Arial, sans-serif; font-size:13px; color:#333333'>Dear 123,<br /><br />Greetings From Eyemails,<br /><br />Kindly check below the Full Statistics Statement of your all E-mail Shot Campaigns :<br /><br /><br /><tr><td align='center'>" body1 += body body1 += "</td></tr><tr><td><br /><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA'>Hope you had a fruitful campaigns.</span><br /><br /><span style='font-size:9.0pt;font-family:Arial,sans-serif;color:#333333'>Kind Regards,</span><span style='font-size:12.0pt;font-family:Times New Roman,serif;color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='color:#CA2E34'>Eyemails Team<br /></span><span style='font-size:8.0pt;font-family:Arial,sans-serif;color:#333333'>Increase revenue, Boost sales, Generate leads, Target potential clients, Build brand awareness<br>Generate website - facebook page visitors, Expand its industry & business market | Customer Service<br><br></span><span style='font-size:9.0pt;font-family:Arial,sans-serif;color:#CA2E34'>E</span><span style='font-size:9.0pt;font-family:Arial,sans-serif;color:#333333'>: <a href='mailto:support@eyemails' style='text-decoration:none; color:#333333'>support@eyemails</a> | </span><span style='font-size:9.0pt;font-family:Arial,sans-serif;color:#CA2E34'>Web</span><span style='font-size:9.0pt;font-family:Arial,sans-serif;color:#333333'>: <a href='eyemails/' style='text-decoration:none; color:#333333'>www.eyemails </a></span><br></td></tr></table>" Try ' mMailmessage.From = New MailAddress(clt_email.Text.Trim.ToLower.Replace("'", "''")) mMailmessage.From = New MailAddress(".......") mMailmessage.Headers.Add("Content-Type", "multipart/related") mMailmessage.Headers.Add("Content-Disposition", "inline") Dim pathof As String = "" Dim typeofimg As String = "" Dim i = 0 Dim regexImgSrc As String = "<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>" Dim matchesImgSrc As MatchCollection = Regex.Matches(body, regexImgSrc, RegexOptions.IgnoreCase Or RegexOptions.Singleline) Dim htmlContent As AlternateView = AlternateView.CreateAlternateViewFromString(body1, Nothing, "text/html") Dim image(matchesImgSrc.Count) As Object For Each m As Match In matchesImgSrc Dim href As String = m.Groups(1).Value If Not href.StartsWith("http:") Then pathof = Path.GetExtension(href) Select Case pathof Case (".jpg") typeofimg = "image/jpeg" Exit Select Case (".png") typeofimg = "image/png" Exit Select Case (".gif") typeofimg = "image/gif" Exit Select Case (".ico") typeofimg = "image/x-icon" Exit Select End Select image(i) = New LinkedResource(href, typeofimg) image(i).ContentId = "Image" & i.ToString image(i).TransferEncoding = Net.Mime.TransferEncoding.Base64 htmlContent.LinkedResources.Add(image(i)) body1 = body1.Replace(href, "cid:Image" & i.ToString) i = i + 1 End If Next mSmtpClient.Credentials = New System.Net.NetworkCredential(".....", "....") mSmtpClient.Port = "587" mMailmessage.Subject = "587" mMailmessage.IsBodyHtml = True mMailmessage.AlternateViews.Add(htmlContent) mMailmessage.Body = Nothing mMailmessage.Priority = MailPriority.High mSmtpClient.Send(mMailmessage) Catch ex As Exception Response.Write(ex.StackTrace) Finally If Not mMailmessage Is Nothing Then mMailmessage = Nothing End If If Not mSmtpClient Is Nothing Then mSmtpClient = Nothing End If End Try

你能帮我说清楚原因吗?在这段代码中: 为什么图像不是嵌入式发送的,收到后不会在邮件正文中查看?

Can you help me know the reason in this code : why the images are not sent embedded and is not viewed in the body of mail when received?

推荐答案

你'在添加到LinkedResources之前添加Linkedsourceobject.ContentType属性。检查以下示例代码。 You've to add Linkedsourceobject.ContentType property before you adding into LinkedResources. Check the following sample codes. Dim htmlview As AlternateView = AlternateView.CreateAlternateViewFromString(txtMessage.Text, Nothing, "text/html") Dim img1 As New LinkedResource("Yourpath\IMG1.jpg") img1.ContentId = "IMG1" img1.ContentType = New ContentType("image/html") htmlview.LinkedResources.Add(img1)

问候, BlueSathish

Regards, BlueSathish

更多推荐

将图像嵌入电子邮件正文问题

本文发布于:2023-11-09 03:04:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   电子邮件   正文

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!