使用vb在asp.net中发送电子邮件

时间:2014-03-27 20:21:47

标签: asp.net email

错误:SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。

了解更多信息

我尝试了所有我可以为此错误做的事情,但无法解决这个问题。请帮忙!! 我发送电子邮件的.net代码如下:

  Try
        Dim oMsg As MailMessage = New MailMessage()
        Dim sendr, receivr As MailAddress
        sendr = New MailAddress("username@gmail.com")
        receivr = New MailAddress(TextBox4.Text)
        oMsg.From = sendr
        oMsg.To.Add(receivr)
        oMsg.Subject = "Asp.net testing"
        oMsg.IsBodyHtml = True
        oMsg.Body = "Hi everyOne"
        'oMsg.BodyFormat = MailFormat.Html
        'oMsg.Body = "<HTML><BODY><B>Dear " & TextBoxName.Text & "</B></br></br>Congratulations! You have been successfully registered.</br></br>"
        'oMsg.Body = oMsg.Body & "Your Username is: " & TextBox1.Text & "</br>Your Password is: " & TextBox2.Text & " </br>Regards,</br>team SMVDU.</BODY></HTML>"

        Dim client As SmtpClient = New SmtpClient()
        Dim cred As System.Net.NetworkCredential = New System.Net.NetworkCredential("username@gmail.com", "*******", "smtp.gmail.com")
        client.Credentials = cred
        client.Host = "smtp.gmail.com"
        client.Port = 587
        client.DeliveryMethod = SmtpDeliveryMethod.Network
        client.EnableSsl = True
        client.UseDefaultCredentials = False
        client.Send(oMsg)
        Response.Write("<script>alert('E-mail sent')</script>")
    Catch ex As Exception
        Response.Write("" & ex.Message)
    End Try

我正在使用windows 7 home basic。所有可以给出的东西都是正确的,即电子邮件,密码来自我身边。

0 个答案:

没有答案