Hide Attachments when using Net.Mail in VB.Net?

Posted on 2008-11-05
Last Modified: 2012-05-05

I am currently using net.mail to send an email with 2 images which is working fine, however the images I have embedded in the html email also show as attachments.

is it possible to hide them from showing as attachments?

When using Outmail, I used to use..

.Attachments.Add("LINK TO IMAGE", , Len(.Body))

However this does not work using net.mail. Can anyone show me how to do this?
I have attached a code snippet of the code I am using to add the attachments.


.Attachments.Add(New System.Net.Mail.Attachment("LINK TO IMAGE"))

Open in new window

Question by:m0tSiE
    LVL 83

    Expert Comment

    You said that you are embedding the photos in the email but the code snippets suggest that you are adding an attachment so the images would appear as attachments.

    Author Comment


    I have tried using the code below to add it as a linked resource, however the image does not show in the email.

    Dim logo As New Net.Mail.LinkedResource("Resources\logo.JPG")
            logo.ContentId = "Logo"

            Dim bar As New Net.Mail.LinkedResource("Resources\bar.JPG")
            bar.ContentId = "Bar"

    I have then called the resources using <img src=cid:Logo> in the html of the email.

    Any ideas?


    LVL 83

    Accepted Solution


    Author Comment


    I am now using the below code which uses the LinkedResource, however the paperclip icon still shows, along with the attachments.

    Any idea how I can hide this?
            'create the mail message
            Dim mail As New MailMessage()
            'set the addresses
            mail.From = New MailAddress("TO")
            'set the content
            mail.Subject = "This is an email"
            'first we create the Plain Text part
            Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")
            'then we create the Html part
            'to embed images, we need to use the prefix 'cid' in the img src value
            'the cid value will map to the Content-Id of a Linked resource.
            'thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
            Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo>", Nothing, "text/html")
            'create the LinkedResource (embedded image)
            Dim logo As New LinkedResource("c:\temp\logo.gif")
            logo.ContentId = "companylogo"
            'add the LinkedResource to the appropriate view
            'add the views
            Dim mailclient As New Net.Mail.SmtpClient
            Dim basicAuthenticationInfo As New Net.NetworkCredential("USER", "PASS")
            mailclient.Host = "SMTP SERVER"
            mailclient.UseDefaultCredentials = False
            mailclient.Credentials = basicAuthenticationInfo

    Open in new window

    LVL 83

    Expert Comment

    I dont see any reason why the attachement icon is still appearing.

    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now