Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
'wt wrong in this codes ?
VB
Imports System.Net.Mail
Imports System.Net.Mime
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("Accountname","yourpassword")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"
            e_mail = New MailMessage()
            e_mail.From = New MailAddress("yourname@gmail.com") 'self emaling 
            e_mail.To.Add("yourname@gmail.com")' self email 
            e_mail.Subject = "Email Sending with image"
            'the current folder of the compiled file has a image named 1.jpg
            Dim path As String = "1.jpg"
            Dim imageLink As New LinkedResource(path)
            imageLink.ContentId = "myImage"
            Dim altView As AlternateView = AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:myImage/>" + "<br></body></html>", Nothing, MediaTypeNames.Text.Html)
            altView.LinkedResources.Add(imageLink)
            e_mail.AlternateViews.Add(altView)
            e_mail.IsBodyHtml = True
            e_mail.Body = ""
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")
        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Me.Text = "this email was test by vimal singh "
    End Sub
End Class</br>
Posted
Updated 11-Jul-16 11:13am
v3
Comments
[no name] 3-Aug-15 7:10am    
Well you didn't format your code so that it's readable.
If you had formmatted your code so that it would be readable, you did not ask a question or describe a problem with your code.

In email, you can simply embed an image element which would hold the image. Just make sure that the link you pass is correct. Mostly, HTTP or HTTPS protocol would also be required, because the image file exists on your server not theirs. Like this,

XML
"<html>
  <body>
    <img src="http://www.example.com/images/file.png" alt="image-name" />
  </body>
</html>"


A few helpful posts for generating HTML emails include:
http://webdesign.tutsplus.com/articles/creating-a-simple-responsive-html-email--webdesign-12978[^]
http://stackoverflow.com/questions/886728/generating-html-email-body-in-c-sharp[^]
http://www.creativebloq.com/netmag/how-create-great-looking-responsive-html-emails-81412552[^]

Simple HTML document is sent as the email body, and email client would render that on screen.
 
Share this answer
 
Comments
Member 10974007 3-Aug-15 7:28am    
i dont wanna have a external image host as they have rending problems.
Afzaal Ahmad Zeeshan 3-Aug-15 7:30am    
I am not asking for an external image. The website is your own whose address is going to be used. Your website (on email client) would be the external website, in that case you have to provide it with HTTP protocol.
Hi I think u r try to send image using ur link,in ur link Path need to give correct server path ,simply 1.png not work.
 
Share this answer
 
Comments
Member 10974007 3-Aug-15 7:19am    
image is not rending and its renamed in gmail .............
Member 10974007 3-Aug-15 7:22am    
'the current folder of the compiled file has a image named 1.jpg
save a small image in the saved file & compiled of the same folder
Aravindba 3-Aug-15 7:32am    
Hi just now i try ur code,i am passing image path like this
Dim path As String = "C:\inetpub\wwwroot\LoadMore\image\1340094141_Program-Group.png"
And when i receive mail ,i can see image as attachment with no extension and download image,so when i open with windows photo viewer i can view.

Whats ur problem ? error in mail sending or file not in email attachment ?
if image path problem then try this
Dim path As String=System.Windows.Forms.Application.StartupPath + "/1.jpg"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900