Link to home
Start Free TrialLog in
Avatar of m0tSiE
m0tSiE

asked on

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

Hi,

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.

Thanks,

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

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of m0tSiE
m0tSiE

ASKER

Thanks,

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?

Thanks,

Paul.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of m0tSiE

ASKER

Thanks.

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")
        mail.To.Add("FROM")
 
        '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
        htmlView.LinkedResources.Add(logo)
 
        'add the views
        mail.AlternateViews.Add(plainView)
        mail.AlternateViews.Add(htmlView)
 
        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
        mailclient.Send(mail)

Open in new window

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

ASKER

Cheers.