【问题标题】:SMTP Mail Error, Failure Sending MailSMTP 邮件错误,发送邮件失败
【发布时间】:2014-04-08 02:05:52
【问题描述】:

当我想在提交表单时发送电子邮件时遇到问题。问题是 SMTP 邮件错误。运行它时,我收到消息“发送邮件失败”。对于内部执行“无法连接到远程服务器”。以下是我的代码:

    Dim conn As New MySql.Data.MySqlClient.MySqlConnection

    Dim strConnectionString As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString

    Try
        conn.ConnectionString = strConnectionString
        conn.ConnectionString = "server=localhost;user id=root;persistsecurityinfo=False;database=test;password=1234"
        conn.Open()





    Catch ex As MySql.Data.MySqlClient.MySqlException
        MessageBox.Show(ex.Message)
    End Try


    Dim sqlConn As New MySqlConnection(strConnectionString)
    sqlConn.Open()
    Dim sqlComm As New MySqlCommand()

    sqlComm.Connection = sqlConn


    Dim msg As MailMessage
    Dim email As String = String.Empty
    Dim SmtpServer As New SmtpClient("smtp.gmail.com", 587)

    msg = New MailMessage()

    email = TextBox3.Text.Trim()
    'sender email address
    msg.From = New MailAddress("****s@gmail.com")
    'Receiver email address
    msg.[To].Add(email)
    msg.Subject = "Change Request have Been Submitted By:"
    msg.Body = "Hi " & TextBox1.Text.Trim() & "!" & vbLf & "Thanks for Submitted the Change Request Online " & vbLf & "Thanks!"
    msg.IsBodyHtml = True
    SmtpServer.Credentials = New NetworkCredential("****s@gmail.com", "******")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    SmtpServer.Send(msg)'THIS LINE IT SHOW THE ERROR'

    ' UserControl()
    Try
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Your Change Request have been submitted.');", True)
    Catch ex As Exception
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Error occured : " & ex.Message.ToString() & "');", True)
        Return
    Finally

        email = String.Empty
        sqlConn.Close()
        sqlComm.Dispose()
    End Try
    Response.Redirect("Default.aspx")
End Sub>

【问题讨论】:

    标签: asp.net-mvc vb.net email smtp


    【解决方案1】:

    这是因为你使用了错误的端口号,google 的 gmail 使用端口 465,更改 587 应该可以工作(前提是用户名+密码正确)。

    【讨论】:

    • 是的..它可以工作,但我在'msg.[To].Add(email)'行收到另一个错误,错误{“指定的字符串不是电子邮件所需的形式地址。”}
    • @kolapopo 你在文本框中输入了什么?应该是标准电子邮件,例如:me@mydomain.com
    • 我修复了它@bensonsearch,但在“SmtpServer.Send(msg)”发送邮件失败时未出现此错误。
    • 我需要其余的错误,但我想您的用户名和密码不正确
    猜你喜欢
    • 2013-09-01
    • 2015-08-27
    • 2014-02-17
    • 2017-02-09
    • 2014-10-26
    • 2018-01-18
    • 1970-01-01
    • 2015-11-20
    • 2023-03-10
    相关资源
    最近更新 更多