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


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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
m0tSiEAuthor Commented:

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?



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

m0tSiEAuthor Commented:

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

I dont see any reason why the attachement icon is still appearing.
m0tSiEAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.