【问题标题】:"Pinging" an email address using VB.Net coding使用 VB.Net 编码“ping”一个电子邮件地址
【发布时间】:2012-05-25 06:30:12
【问题描述】:

在 VB.Net 中是否有办法“Ping”一个电子邮件地址,以查看该电子邮件是否是真实的,不会出现任何错误?

如果是,您能否展示一下 VB.Net 编码的实现方式?

我计划在需要客户电子邮件的应用程序中使用它,并且在电话接听者在保存客户详细信息之前将其输入表单时验证它会很好。

这是我们用来向客户表中的所有客户发送电子邮件促销的代码:

Private Sub RibbonButtonSendTestEmail_Click(sender As System.Object, e As System.EventArgs) Handles RibbonButtonSendTestEmail.Click

    Dim SmtpServer As New SmtpClient()
    Dim mail As New MailMessage()
    Dim strSqlStatement As String = "Select CustomerName, Email " & _
                               "From Customers "

    Using objSqlCommand As SqlCommand = New SqlCommand(strSqlStatement, ObjConnection)

        With objSqlCommand

            ' Open the SqlConnection before executing the query.
            '---------------------------------------------------
            Cursor = Cursors.WaitCursor

            ObjConnection.Open()

            Dim objDataReader As SqlDataReader = .ExecuteReader()

            ' Go through all the customers and send out the promotion emails.
            '----------------------------------------------------------------
            If objDataReader.HasRows Then

                SmtpServer.Host = TextBoxSMTPServer.Text
                SmtpServer.Port = TextBoxPort.Text

                If TextBoxUseSSL.Text = "Yes" Then
                    SmtpServer.EnableSsl = True
                Else
                    SmtpServer.EnableSsl = False
                End If

                If TextBoxUseDefaultCredentials.Text = "Yes" Then
                    SmtpServer.UseDefaultCredentials = True
                Else
                    SmtpServer.UseDefaultCredentials = False
                End If

                SmtpServer.Credentials = New Net.NetworkCredential(TextBoxUserName.Text, TextBoxPassword.Text)

                While objDataReader.Read()

                    Try
                        mail.To.Add(objDataReader("Email").ToString)
                        mail.From = New MailAddress(TextBoxEmailFrom.Text)
                        mail.Subject = "Promotion: " & TextBoxID.Text
                        mail.Body = "Dear " & objDataReader("CustomerName") & "," & vbCrLf & vbCrLf & TextBoxPromotionBodyText.Text

                        SmtpServer.Send(mail)

                    Catch exSMTP As SmtpException
                        MessageBox.Show("Sorry, I could not send an email for: " & _
                                    vbCrLf & objDataReader("CustomerName") & "." & vbCrLf & _
                                    "Please make sure it is correct.", _
                                    "Error")

                    Catch exFormat As FormatException
                        MessageBox.Show("Sorry, this customer's email is not properly formatted: " & _
                                    vbCrLf & objDataReader("CustomerName") & "." & vbCrLf & _
                                    "Please make sure it is correct.", _
                                    "Error")
                    End Try
                End While

                LabelEmail.Text = "Sent email promotions to the customers."
            End If

            objDataReader.Close()
            ObjConnection.Close()

            Cursor = Cursors.Default
        End With ' objSqlCommand
    End Using ' objSqlCommand
End Sub

【问题讨论】:

标签: vb.net email ping verify


【解决方案1】:

是的,完全有可能:

1 DNS 查找域的 MX 记录

  • 可能有多个,您可以选择任何人,但从技术上讲,偏好指标最低的那个是首选。

2 TCP 连接邮件服务器(端口 25)

  • 打个招呼:HELO
  • 表明自己的身份:mail from:<test@example.com>
  • 说出你要写信给谁:rcpt to<testaddress@example.com>
  • 此时服务器将回复响应,您将收到 OK550 错误消息(例如:The email account that you tried to reach does not exist
  • 断开连接,消息将被丢弃。

但是老兄,你想让 VB 代码来做这个吗?您只需要一个 DNS 谈话片段和 TCP 连接构建片段(或者可能有一些 SMTP 库可以为您完成所有这些工作 - 或者为您提供灵感来自己解决这个问题)。不要忘记,您可能可以找到一个 C# 代码示例,并使用 Visual Studio 的转换工具将其切换到 VB。

注意

许多域都有黑洞/万能...那么...将发件人的地址卖给垃圾邮件发送者?)在这两种情况下,您都不会收到550 消息,因此您永远无法确定。

【讨论】:

    【解决方案2】:

    最可靠的方法是发送一封测试电子邮件,让收件人通过单击一个链接来验证收据,然后您阅读该链接并将电子邮件标记为活动。

    您应该使用正则表达式对电子邮件的语法进行原始检查,但除此之外,验证电子邮件最可靠的方法是尝试发送并确认收据。

    【讨论】:

    • 感谢大家的回复。我正在对帖子进行更新,以便您知道我是如何发送电子邮件的。这是一个循环,遍历数据库中的每个客户,并在我们创建促销活动时发送促销电子邮件。
    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2017-07-23
    • 2013-07-29
    相关资源
    最近更新 更多