Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application while sending the printticket on gmail, it didnt show my logo image(jpeg) on the mail..why please help me sir...!
Posted
Comments
Sandeep Mewara 17-Jul-12 11:17am    
Where is the image referred from? Is it part of email or a link from somewhere?
[no name] 17-Jul-12 11:20am    
Having carefully reviewed and debugged the code that you posted that demonstrates your problem, I have concuded that your email traveled too closely to www.blackhole.com and the logo got ripped from your printticket and lost.
WoodenLegNamedSmith 17-Jul-12 13:57pm    
and this comment helps how? lol
[no name] 17-Jul-12 15:32pm    
Admittedly it would only be helpful if the next time the OP posts a question he is reminded by this comment that he should follow the guidelines and post the code that is having trouble with as well as a clear description of the problem that he is having.
WoodenLegNamedSmith 17-Jul-12 15:49pm    
Well said...

You have to make use of a combination of both Alternate Views and Linked resources in order to embed images in e-mail.

VB
Imports System.Net.Mail
Imports System.Net.Mime

Public Class EmailMessage

Sub New(ByVal body As String, ByVal isHtml As Boolean, Optional ByVal subject As String = DefaultSubject)

        p_messagesubject = subject
        Message.Subject = MessageSubject
        Message.Priority = MailPriority.High
        Message.IsBodyHtml = isHtml

        If isHtml Then
            p_htmlmessagebody = body
            Dim htmlContent As ContentType
            htmlContent = New ContentType("text/html")
            Dim htmlView As AlternateView
            htmlView = AlternateView.CreateAlternateViewFromString(HtmlMessageBody, Nothing,
 MediaTypeNames.Text.Html)
            
            Dim logo As LinkedResource = New LinkedResource("c:\mylogo.jpg")
            logo.ContentId = "MyEmbeddedLogo"
            logo.TransferEncoding = System.Net.Mime.TransferEncoding.Base64

            htmlView.LinkedResources.Add(logo)
            Message.AlternateViews.Add(htmlView)
        Else
            p_messagebody = body
            Message.Body = MessageBody
        End If

    End Sub

End Class


Now, in order for the logo to show up you have to have a standard HTML img tag inside the HtmlMessageBody whose src attribute is set to the name of the ContentId

HTML
<img src="cid:MyEmbeddedLogo" />
 
Share this answer
 
Comments
ArtificerGM 17-Jul-12 14:01pm    
Good post, good code!
Hi,
You can use "System.Net.Mail.LinkedResource" to do the job.

Embed an Image in Email using ASP.NET[^] would be a nice article for your solution.


--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900