I'm attempting to display an embedded image in an email (asp.net using a System.net.mail linked resource) but can't find the proper file path to the image in my website (sample of my code is copied at bottom). The image exists in both the root and the /images folder. I have tried dozens of file paths and none work. This path returned by Dim mypath As String = Server.MapPath("/") is E:\web\myusername\ The file exists in both the root and the ~/Images folder of my website. Every attempt to map to the file in the website root or /Images folder has failed. Seems I'm missing something that should be very basic... Thanks, Stewart Code: Public Sub EmbedImages() Dim mail As New MailMessage() Dim path As String = Server.MapPath("/") 'Returns E:\web\xyz\ Dim MyFilename As String = path + EVERYTHING I TRY IS WRONG 'the file House2-color.png exists in the root of the website project and the /Images directory Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain") Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:House2-color>", Nothing, "text/html") 'create the LinkedResource (embedded image) Dim logo As New LinkedResource(MyFilename) logo.ContentId = "House2-color" 'add the LinkedResource to the appropriate view htmlView.LinkedResources.Add(logo) 'add the views mail.AlternateViews.Add(plainView) mail.AlternateViews.Add(htmlView) 'send the message Dim SmtpMail As New SmtpClient Dim basicAuthenticationInfo As New System.Net.NetworkCredential("postmaster@xyz", "zyx") SmtpMail.EnableSsl = False SmtpMail.Host = "mail.xyz.net" SmtpMail.UseDefaultCredentials = False SmtpMail.Credentials = basicAuthenticationInfo SmtpMail.Send(mail) End Sub
Fixed, sort of Turns out the missing image "problem" isn't quite what I thought. Hotmail on Safari does not show the image (was viewing from my Mac book). Hotmail on IE does show the embedded image correctly. So, I'm getting the path correct, at least...
Ahhh so it might just be a Browser/computer setting perhaps. Maybe some kind of security feature on the browser's settings. Glad to hear you worked it out on your own.