Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<big>In my code i firstly passing image to database the i want use that image to attach and mail , please HELP ME !!!!!!!!!</big> </pr<pre><pre>



Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       Dim con As New SqlConnection
       Dim cmd As New SqlCommand
       Dim cmd1 As New SqlCommand

       Try
           con.ConnectionString = "Data Source=localhost;Initial Catalog=mydb;Integrated Security=True"
           cmd.Connection = con
           con.Open()
           cmd = New SqlCommand(" SELECT systemimage FROM efficiency2  WHERE   ( username = '" & lblusername.Text & "' )", con)
           Dim imAgeData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
           If Not imAgeData Is Nothing Then
               Using ms As New MemoryStream(imAgeData, 0, imAgeData.Length)
                   ms.Write(imAgeData, 0, imAgeData.Length)
                   profilepic.Image = Image.FromStream(ms, True)
               End Using

           End If
           'con.Open()
           cmd = New SqlCommand(" SELECT userimage FROM  efficiency2 WHERE   (username = '" & lblusername.Text & "' )", con)
           Dim imAgeData1 As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
           If Not imAgeData1 Is Nothing Then
               Using ms1 As New MemoryStream(imAgeData1, 0, imAgeData.Length)
                   ms1.Write(imAgeData1, 0, imAgeData1.Length)
                   profilepic1.Image = Image.FromStream(ms1, True)
               End Using

           End If
           'change the data fields names and table according to your database
           cmd.CommandText = " SELECT TOP (1)id,username,systemtime,Timer_hr,Timer_mint,Timer_sec,systemImage,userimage FROM efficiency2 WHERE   (username = '" & lblusername.Text & "' )ORDER BY id DESC"
           'con.Open()
           'con.Open()

           Dim lrd As SqlDataReader = cmd.ExecuteReader()
           If lrd.HasRows Then

               lrd.Read()
           End If

           ''Dim cmd1 As New SqlCommand
           'cmd1.Connection = con
           ''change the data fields names and table according to your database
           'cmd1.CommandText = " SELECT TOP (1) id, Name, Address, Email, Phonenumber, Password, photo, Rolls FROM regisration_form ORDER BY id DESC"

           'Dim lrd2 As SqlDataReader = cmd1.ExecuteReader()
           'If lrd2.HasRows Then


           '    If lrd2.Read() Then
           '        lblid.Text = lrd("id").ToString()
           '        lblname.Text = lrd("Name").ToString()
           '        lblroll.Text = lrd("Rolls").ToString()
           '        Address.Text = lrd("address").ToString()
           '        Email.Text = lrd("Email").ToString()
           '        phonenumber.Text = lrd("phonenumber").ToString()
           '    End If
           'End If
           'End If
           'con.Close()
           'con.Open()


           'Do something here

           lblname.Text = lrd("username").ToString()
           lblroll.Text = lrd("systemtime").ToString()
           Address.Text = lrd("Timer_hr").ToString()
           Email.Text = lrd("Timer_mint").ToString()
           phonenumber.Text = lrd("Timer_sec").ToString()
           'Password = Label18.Text
           lrd.Close()

       Catch ex As Exception
           MessageBox.Show("Error while connecting to SQL Server." & ex.Message)

       Finally
           con.Close() 'Whether there is error or not. Close the connection.
       End Try



       Using mail As New MailMessage
           mail.From = New MailAddress("admissioncsabnic@gmail.com")
           mail.To.Add(destination.Text$)
           mail.Body = lblname.Text$
           'If Not OpenFileDialog1.FileName = vbNullString Then
           'Dim attach As New Attachment()
           Dim attach As New System.Net.Mail.Attachment(profilepic1.ImageLocation)
           'MyMailMessage.Attachments.Add(attchm)
           mail.Attachments.Add(attach)
           'End If
           mail.Subject = lblname.Text$
           mail.Priority = mail.Priority.Normal
           Using SMTP As New SmtpClient
               'SMTP.EnableSsl = True
               'SMTP.Port = "587"
               'SMTP.Host = "smtp.gmail.com"
               'SMTP.Credentials = New Net.NetworkCredential("ujjawal.vermanu53@gmail.com", "bholenath1994")
               'SMTP.Send(mail)

               SMTP.Host = "smtp.gmail.com"
               SMTP.EnableSsl = True
               Dim NetworkCred As NetworkCredential = New NetworkCredential("admissioncsabnic@gmail.com", "sachin@6")
               SMTP.UseDefaultCredentials = True
               SMTP.Credentials = NetworkCred
               SMTP.Port = 587
               SMTP.Send(mail)
           End Using
       End Using
e>

What I have tried:

try to attach database image to mail. or try to attach image though picturebox. to sending mail. :( PLEASE HELP ME
Posted
Updated 9-Jul-17 20:06pm
Comments
Richard Deeming 10-Jul-17 13:53pm    
And if that's your real GMail credentials that you've just posted to a public forum, then you should change the password on both accounts immediately!

1 solution

 
Share this answer
 
v2

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