-1

班级代码:-

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“按钮子”内的代码

Dim objemail As New SendEmail
objemail.Mailto = txtEmail.Text
objemail.email()
LabelEmail.Text = "The email has been sent"

指定的字符串不是电子邮件地址所需的格式,我试图在“mailto”字段中使用有效的电子邮件,我删除了属性和字段中的所有内容,但尚未解决,,,帮助:D

任何灵魂?

4

1 回答 1

0

txtEmail.Text当用户输入值时,您是否验证有效的电子邮件地址?如果没有,请这样做。

你在email()方法中有一些例外吗?

于 2012-04-09T04:50:14.683 回答