0

我的代码正在向我的数据库添加一个用户。我正在尝试让我的网站发送一封带有密码的电子邮件,以验证电子邮件帐户是否合法。

首先,我试图让它发送一封基本的测试电子邮件。然后我计划在我的网站的链接中添加密码来验证它。

我的问题是我的代码没有发送基本的测试电子邮件。

Imports System.Data.SqlClient
Imports System.Net.Mail

Partial Class Account_Register
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles     Me.Load
    RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
End Sub



Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
    FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)

    Dim MyMailMessage As New MailMessage()
    ' MyMailMessage.IsBodyHtml = True
    MyMailMessage.From = New MailAddress("NAME@gmail.com")
    MyMailMessage.To.Add("Name@yahoo.com")
    MyMailMessage.Subject = "Email Confirmation"
    MyMailMessage.Body = "TESTING"
    'MyMailMessage.Body = "<html>" & RegisterUser.UserName & "Link: $" & "<br/> " & "</html>"

    'Create the SMTPClient object and specify the SMTP GMail server
    Dim SMTPServer As New SmtpClient("smtp.gmail.com")
    SMTPServer.Port = 588
    SMTPServer.Credentials = New System.Net.NetworkCredential("NAME@gmail.com", "Password")
    SMTPServer.EnableSsl = True

    Try
        SMTPServer.Send(MyMailMessage)
        'MessageBox.Show("Email Sent")
    Catch ex As SmtpException
        'MessageBox.Show(ex.Message)
    End Try


    Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
    If String.IsNullOrEmpty(continueUrl) Then
        continueUrl = "~/"
    End If

    Response.Redirect(continueUrl)
End Sub
End Class

有什么帮助吗?

4

2 回答 2

1

更改端口号 Gmail SMTP 端口为:465

用这个

 SMTPServer.Port = 465
于 2013-05-15T07:11:52.843 回答
0

所以我最终不得不使用 Port = 587

感谢您的帮助!

于 2013-05-15T08:06:22.243 回答