Member 13258186 Ответов: 1

Как отправить изображение по электронной почте через picture box или как прикрепить файл изображения с помощью picture box?, in VB.NET


<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>

Что я уже пробовал:

попробуйте прикрепить изображение базы данных к почте. или попробуйте прикрепить изображение через picturebox. отправлять почту. : (ПОЖАЛУЙСТА, ПОМОГИТЕ МНЕ

Richard Deeming

И если это ваше реальный" Учетные данные GMail, которые вы только что опубликовали на общедоступном форуме, затем вы должны изменить пароль для обеих учетных записей немедленно!