Image not showing in vb.net
-
Hello I have partly followed this tutorial: Sending email with an embedded image through ASP.NET[^] and, though the user receives his email, when I test my SMTP locally, the plain background image (600px x 600px) does not appear. In Visual Studio (2013), I don't get any errors. The image, emailBG.jpg, is in my Images folder in Solution Explorer, and the code I am using to send plain and HTML emails, and for the background image, is as follows:
Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello. To reset your password....Nothing, "text/plain")
Dim mimeType As ContentType = New ContentType("text/html")
Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("pre> Thanks for any advice.
-
Hello I have partly followed this tutorial: Sending email with an embedded image through ASP.NET[^] and, though the user receives his email, when I test my SMTP locally, the plain background image (600px x 600px) does not appear. In Visual Studio (2013), I don't get any errors. The image, emailBG.jpg, is in my Images folder in Solution Explorer, and the code I am using to send plain and HTML emails, and for the background image, is as follows:
Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello. To reset your password....Nothing, "text/plain")
Dim mimeType As ContentType = New ContentType("text/html")
Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("pre> Thanks for any advice.
-
Please post your question in the forum at the end of the article, so the author sees it.
Hello Richard Thanks for your reply. The article is 10 years old - not sure if the author will even see it. Thanks again.
-
Hello I have partly followed this tutorial: Sending email with an embedded image through ASP.NET[^] and, though the user receives his email, when I test my SMTP locally, the plain background image (600px x 600px) does not appear. In Visual Studio (2013), I don't get any errors. The image, emailBG.jpg, is in my Images folder in Solution Explorer, and the code I am using to send plain and HTML emails, and for the background image, is as follows:
Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello. To reset your password....Nothing, "text/plain")
Dim mimeType As ContentType = New ContentType("text/html")
Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("pre> Thanks for any advice.
Looks like the HTML version of your message has been truncated, so we can't see what styles you've applied. And remember, if you're setting a background image for a
<p>
tag, it will be cropped to the site of that paragraph of text. You probably want to specify the<body>
tag, and put the background image there:Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("<body style=""background:url('cid:emailBG') no-repeat;"">...</body>", Nothing, "text/html")
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Looks like the HTML version of your message has been truncated, so we can't see what styles you've applied. And remember, if you're setting a background image for a
<p>
tag, it will be cropped to the site of that paragraph of text. You probably want to specify the<body>
tag, and put the background image there:Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("<body style=""background:url('cid:emailBG') no-repeat;"">...</body>", Nothing, "text/html")
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Yes, you're right. I do have that against 'p' at the moment:
("
Hello " & strEmailValue & "
To reset your password....etc
", Nothing, "text/html")
I will take on board what you suggest about 'body' as opposed to 'p' and use your 'cid:email.BG'. Would I still need these two lines that follow the above line I have posted above:
Dim Logo As New LinkedResource(Server.MapPath("~/Images/emailBG.jpg"), "image/jpeg") 'embedded image
Logo.ContentId = "emailBG"Isn't 'Logo.ContentId = "emailBG"' a repetition of your 'cid:emailBG'? Thanks. Can you see this message though it is not in 'Preview'?
-
Yes, you're right. I do have that against 'p' at the moment:
("
Hello " & strEmailValue & "
To reset your password....etc
", Nothing, "text/html")
I will take on board what you suggest about 'body' as opposed to 'p' and use your 'cid:email.BG'. Would I still need these two lines that follow the above line I have posted above:
Dim Logo As New LinkedResource(Server.MapPath("~/Images/emailBG.jpg"), "image/jpeg") 'embedded image
Logo.ContentId = "emailBG"Isn't 'Logo.ContentId = "emailBG"' a repetition of your 'cid:emailBG'? Thanks. Can you see this message though it is not in 'Preview'?
Yes, you'd still need the linked resource. The
cid:
is the protocol which lets the mail client know that the image should be loaded from the linked resources in the message, rather than trying to load it from a file or a website. Socid:emailBG
in the HTML is a URL that points to the embedded resource with the content ID set toemailBG
. How do I embed images in an email?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Yes, you'd still need the linked resource. The
cid:
is the protocol which lets the mail client know that the image should be loaded from the linked resources in the message, rather than trying to load it from a file or a website. Socid:emailBG
in the HTML is a URL that points to the embedded resource with the content ID set toemailBG
. How do I embed images in an email?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks. I am familiar with that link - been hours on this! I will give it all a go and fingers crossed! Many thanks again for your help.