English 中文(简体)
使用 VB. Net 编码的电子邮件地址
原标题:"Pinging" an email address using VB.Net coding

VB.

如果有,请显示 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
最佳回答

是的,这是完全可能的:

1 <%1 DNS 查找域名 的 MX 记录

  • There may be multiples, you can pick anyone, although technically the one with the lowest preference indicator is the prefered one.

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

  • Say hello: HELO
  • Identify yourself: mail from:<[email protected]>
  • Say who you re writing to: rcpt to<[email protected]>
  • At this point the server will reply with a response, you ll get an OK or a 550 error with a message (like: The email account that you tried to reach does not exist)
  • Disconnect and the message will be dropped.

但是,老兄,你想要VB代码来做到这一点吗?你只需要一个DNS谈话片和TCP连接建筑片(或者可能有些SMTP图书馆可以为你做这一切-或者给你灵感来自己弄清楚)。不要忘记,你可能能找到一个 C# 代码示例,并使用视觉工作室转换工具将其切换为 VB 。

<强 > 注

许多域都有黑洞/ 抓获所有... 前者将接受任何电子邮件地址, 如果该地址无效, 则删除它, 后者将接受任何电子邮件地址, 并将其转发到一个中央账户( 无法保证会发生什么... 将发送者地址卖给垃圾邮件?) 在这两种情况下, 您都得不到 < code> 550 < / code > 消息, 所以您永远无法确定 。

问题回答

最可靠的方法就是发送测试邮件, 并点击链接来验证收件人的收件, 然后您读到并标记电子邮件为活动 。

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





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签