Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Embedded image within email from embedded resource

$
0
0
Hello.

Seems there are hundreds of articles on how to embed an image within an email via code.

But I've been unable to find one to help me figure out how to make it work with an embedded resource image.

I do not want to have my final executable copying the image out to a folder then attaching it as a linked resource in the email.

I want the code that handles the new email generation to look at the application resource and grab the logo.png file from here and then attach the image as a linkedresource to the email for inline distribution of the logo within the html body.

Is this actually possible with .net?

I'm hoping someone says yes!

Code:

        Dim msg As New MailMessage("sender mail address", "recipient mail address")
        msg.Subject = "subject"
        msg.IsBodyHtml = True

        Dim View As AlternateView
        Dim resource As LinkedResource
        Dim client As SmtpClient
        Dim msgText As New StringBuilder

        msgText.Append("text intro")
        msgText.Append("text message.")

        'create an alternate view for your mail
        View = AlternateView.CreateAlternateViewFromString(msgText.ToString(), Nothing, "text/html")

        'link the resource to embed
      resource = New LinkedResource((Server.MapPath("Images\logo.png")))

        'Name the resource
        resource.ContentId = "Image1"

        'Add the resource to the alternate view
        View.LinkedResources.Add(resource)

        'Add the view to the message
        msg.AlternateViews.Add(View)

        client = New SmtpClient()
        client.Host = "mailhost" 'smtp server

        'smtp server SSL to communicate
        client.Credentials = New Net.NetworkCredential("username", "password")
        client.Send(msg)

what I would like to have is something liek the above line that does this? ( i know logically this is not going to wrk as the data types are different, but to give the gist of it :D

Code:

    resource = New LinkedResource(My.Resources.Resource1.MyLogo)

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>