Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2008-11-05
Medium Priority
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
  • 3
  • 3
LVL 83

Expert Comment

ID: 22893353
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

ID: 22894875

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

CodeCruiser earned 2000 total points
ID: 22896867
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 22902767

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

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

Author Closing Comment

ID: 31513507

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 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