无法通过VB.NET发送文本框数据

时间:2013-06-10 21:29:27

标签: vb.net email timeout

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
    Try
        Dim SmtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        SmtpServer.Credentials = New Net.NetworkCredential("gahlotprayank@yahoo.com", "*******")
        SmtpServer.Port = 465
        SmtpServer.Host = "smtp.mail.yahoo.com"
        mail = New MailMessage()
        mail.From = New MailAddress("gahlotprayank@yahoo.com")
        mail.To.Add("rebelme23@gmail.com")
        mail.Subject = TextBox1.Text
        mail.Body = TextBox2.Text
        SmtpServer.Send(mail)
        MsgBox("ok!")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

我尝试了上面的代码,但得到的错误是“超时”,无法邮寄文本框数据

enter image description here

2 个答案:

答案 0 :(得分:1)

超时可能与服务器有关,与您的文本框值无关。您确定您有权使用yahoo的邮件服务器发送电子邮件吗?

答案 1 :(得分:0)

尝试使用“smtp.gmail.com”端口:587 然后启用电子邮件帐户的“访问安全性较低的应用”选项