[英]SMTP Mail Error, Failure Sending Mail
我要在提交表單時發送電子郵件時遇到問題。 問題是SMTP郵件錯誤。 運行時,我收到消息“發送郵件失敗”。 對於Innerexecption,“無法連接到遠程服務器”。 下面是我的代碼:
<受保護的子btnExit_Click(作為對象發送,作為EventArgs發送)處理btnExit.Click
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>
這是因為您使用了錯誤的端口號,Google的gmail使用了端口465,更改了587,它應該可以工作(只要用戶名和密碼正確)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.