ASP.Net中的电子邮件附件问题

时间:2012-07-02 08:07:53

标签: asp.net email attachment

您好我正试图通过ASP.NET向一些电子邮件发送图片附件。该程序没有任何问题,但我无法在某些电子邮件程序中可视化附加的图片,例如iPhone的Yahoo电子邮件电子邮件程序。我怀疑我没有正确附上图片。 它在我的台式电脑上运行正常

加载电子邮件后,我看不到图片。

   Dim mail As New MailMessage()
    mail.From = New MailAddress("xxxxxxxx", "xxxxxxx")
    mail.To.Add(DirectCast(RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email"), TextBox).Text)
    mail.Subject = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    mail.Body = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    Dim htmlBody As String = "<html><body><DIV style=""background-color:#5B37AE"">"
    htmlBody += "<img height=""70px"" width=""150px"" src=cid:HDIImage /></DIV></body></html>"

    Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody, Nothing, "text/html")
    Dim imageResource As New System.Net.Mail.LinkedResource(Server.MapPath("~/Images/Site/background_main2.png"))
    imageResource.ContentId = "HDIImage"
    htmlView.LinkedResources.Add(imageResource)


    mail.AlternateViews.Add(htmlView)

    Dim j As New SmtpClient
    j.Host = "hostingxxxxx"
    j.EnableSsl = False
    j.Credentials = New System.Net.NetworkCredential("usernam", "passw")

    j.Send(mail)

由于

1 个答案:

答案 0 :(得分:1)

没有必要通过linkedresoruce附加,添加src="http://wwww.mysite.com/myimage.jpg"可以在每个(现代)浏览器中正常工作