班级代码: -
Imports Microsoft.VisualBasic
Imports System.Net.Mail
Public Class SendEmail
Private _Mailto As String = ""
Public Property Mailto() As String
Get
Return _Mailto
End Get
Set(ByVal value As String)
_Mailto = value
End Set
End Property
Private _MailSub As String = ""
Public Property MailSub As String
Get
Return _MailSub
End Get
Set(ByVal value As String)
_MailSub = value
End Set
End Property
Private _MailBody As String = ""
Public Property MailBody As String
Get
Return _MailBody
End Get
Set(ByVal value As String)
_MailBody = value
End Set
End Property
Private _Msg As String = ""
Public ReadOnly Property Msg As String
Get
Return _Msg
End Get
End Property
Public Sub email()
Try
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
mail.From = New MailAddress("email@gmail.com")
mail.[To].Add(_Mailto)
mail.Subject = _MailSub
mail.Body = _MailBody
' mail.Headers.Add("In-Reply-To", 1)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential("email@gamil.com", "password")
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
_Msg = " Check Your Mail "
Catch ex As Exception
_Msg = ex.Message
End Try
End Sub
End Class
ctrl“button sub”中的代码
Dim objemail As New SendEmail
objemail.Mailto = txtEmail.Text
objemail.email()
LabelEmail.Text = "The email has been sent"
指定的字符串不是电子邮件地址所需的格式,我试图在“mailto”字段中使用vaild电子邮件,并且我已经删除了所有的特性和字段,但尚未解决,,,帮助:D
任何灵魂?
答案 0 :(得分:0)
当用户输入值时,您是否验证txtEmail.Text
有效的电子邮件地址?
如果没有,请这样做。
你在email()
方法中得到了一些例外吗?