Email image Embeding
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
2 posts
Page 1 of 1
Hi people i am currently making a program for emailging and i need to email a screen print of one panel it needs to see all the controls in that panel as well as it is going to be populated with pictures like a collarge type deal but well how do i add this image to my email code i have this code for sending to my Gmail
Code: Select all
And that works fine for the text but how can i add the text and the image below the text Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("xprograming.manning516@gmail.com", "************")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("xprograming.manning516@gmail.com")
mail.To.Add("xprograming@gmx.co.uk")
mail.Subject = "Test Mail"
mail.Body = TextBox4.Text
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
try this
change everything as you needed :P

Code: Select all
Sub EmbedImages()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")
'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)
'send the message
Dim smtp As New SmtpClient("127.0.0.1") 'specify the mail server address
smtp.Send(mail)
End Sub 'EmbedImages
Find my programs on Softpedia
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023