Jump to content
Cor3Quad

Transfer textbox data to email via visual basic

Recommended Posts

Vreau ca, ce se scrie in Textbox1 si textbox2 sa se trimita pe un cont de gmail.Am codul :

Imports System.Net.Mail


Public Class Form1

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
CheckBox1.Checked = False
End If
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
CheckBox2.Checked = False
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Enter a Password!")
Else
If TextBox2.Text = "" Then
MsgBox("Enter Email!")
Else
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("email", "mypassword")
SmtpServer.EnableSsl = True
SmtpServer.Port = 465
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("aiciprimesc@gmail.com")
mail.To.Add("aiciprimesc@gmail.com")
mail.Subject = TextBox1.Text
mail.Body = TextBox2.Text
Try
SmtpServer.Send(mail)
Catch ex As Exception
MsgBox("done")
End Try
End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class

Se blocheaza cand dau send si :

A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll

Link to comment
Share on other sites

SmtpServer.EnableSsl = False
Catch ex As Exception When MsgBox(ex.ToString())

+

Exception Mesages Disabled

Acceeasi problema.

Am rezolvat pana la urma :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Enter a Password!")
Else
If TextBox2.Text = "" Then
MsgBox("Enter Email!")
Else
End If
End If
Try
Dim SmtpServer As New SmtpClient
SmtpServer.EnableSsl = True
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential("mailumeu@gmail.com", "PAROLA-REALA")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage
mail.From = New MailAddress("mailumeu@gmail.com")
mail.To.Add("mailumeu@gmail.com")
mail.Subject = TextBox2.Text
mail.Body = TextBox1.Text
SmtpServer.Send(mail)
MsgBox("Done!")
Catch ex As Exception

End Try
End Sub

Edited by Cor3Quad
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...