0

我在这段代码中有问题

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

例外是:指定的字符串不是电子邮件地址所需的格式。:任何灵魂?

4

1 回答 1

0

看起来您正在将 _MailTo 初始化为一个空字符串 (""),然后将“To”电子邮件地址设置为该值。除非您将该字段的值设置为某个有效的电子邮件地址,否则电子邮件发件人不会将空字符串识别为有效的电子邮件地址。

(如果您从给定代码之外设置 MailTo 属性,则需要提供代码以显示您在哪里设置它以及值是什么。)

于 2012-04-09T03:36:24.123 回答