Senden von E-Mails mit Gmail gibt ein time-out Fehler
Testen wir einige Codes zum senden von E-Mails mit Google Mail aus einem Formular, sondern bekommen einen time out error.
Können Sie uns sagen, was fehlt, von diesem code, um die E-Mail-Nachricht gesendet?
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.EnableSsl = True
SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "MyPasswordGoesHere")
SmtpServer.Port = 465
SmtpServer.Host = "smtp.gmail.com"
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail sent")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Update:
Code ändern mit MailBee. Dies ist, wie wir tun, E-Mails an alle Kunden:
Dim strSqlStatement As String = "Select CustomerName, Email " & _
"From Customers " & _
"Where Email Is Not Null"
If IsConnected() Then
' Set up the sql command and lookup the parent.
'----------------------------------------------
Using objSqlCommand As SqlCommand = New SqlCommand(strSqlStatement, ObjConnection)
With objSqlCommand
' Open the SqlConnection before executing the query.
'---------------------------------------------------
Cursor = Cursors.WaitCursor
ObjConnection.Open()
Dim objDataReader As SqlDataReader = .ExecuteReader()
' Go through all the customers and send out the promotion emails.
'----------------------------------------------------------------
If objDataReader.HasRows Then
MailBee.Global.LicenseKey = "My license key goes here."
Dim objSMTP As New Smtp
Dim server As New SmtpServer(TextBoxSMTPServer.Text, TextBoxUserName.Text, TextBoxPassword.Text)
'SmtpServer.Host = TextBoxSMTPServer.Text
'SmtpServer.Port = TextBoxPort.Text
'SmtpServer.Timeout = 100
'If TextBoxUseSSL.Text = "Yes" Then
' SmtpServer.EnableSsl = True
'Else
' SmtpServer.EnableSsl = False
'End If
'If TextBoxUseDefaultCredentials.Text = "Yes" Then
' SmtpServer.UseDefaultCredentials = True
'Else
' SmtpServer.UseDefaultCredentials = False
'End If
'SmtpServer.Credentials = New Net.NetworkCredential(TextBoxUserName.Text, TextBoxPassword.Text)
objSMTP.SmtpServers.Clear()
objSMTP.SmtpServers.Add(server)
While objDataReader.Read()
If objDataReader("Email").ToString <> "" Then
objSMTP.Message.From.AsString = TextBoxEmailFrom.Text
objSMTP.Message.To.AsString = objDataReader("Email").ToString
objSMTP.Message.Subject = "Promotion: " & TextBoxID.Text
objSMTP.Message.BodyPlainText = "Dear " & objDataReader("CustomerName") & "," & vbCrLf & vbCrLf & TextBoxPromotionBodyText.Text
Try
objSMTP.Send()
Catch exBadPassword As MailBeeSmtpLoginBadCredentialsException
MsgBox("The login name or password is not correct.", MsgBoxStyle.Exclamation, "Email")
blnThereWereErrors = True
Catch exBadFromAddress As MailBeeSmtpRefusedSenderException
MsgBox("The sender email must be the same as the user's email address.", MsgBoxStyle.Exclamation, "Email")
blnThereWereErrors = True
Catch ex As Exception
MsgBox(ex.Message)
blnThereWereErrors = True
End Try
End If
If blnThereWereErrors Then
Exit While
End If
End While
If blnThereWereErrors = False Then
MessageBox.Show("Mass emailing has completed." & vbCrLf, _
"Email Message.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If
End If
objDataReader.Close()
ObjConnection.Close()
Cursor = Cursors.Default
End With ' objSqlCommand
End Using ' objSqlCommand
InformationsquelleAutor der Frage Emad-ud-deen | 2012-05-21
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen, eine andere port-Nummer. Sie können nicht verwenden Sie port 465 mit
System.Net.Mail
wie es unterstützt nur "Explizites SSL". Haben Sie einen Blick auf auf dieser Seite für mehr info auf das.Gmail akzeptiert port 25 oder 587, wenn das senden von mail über VB.NET aber mal mit port 465.
Auch sicherstellen, dass Sie
UseDefaultCredentials = False
Haben auch einen Blick auf dieses Beispiel auf, wie E-mail zu senden mit Google Mail in C#, es könnte Ihnen etwas mehr Ahnung.
InformationsquelleAutor der Antwort Matt Wilko
Ich hatte ähnliches problem, in meinem Fall habe ich einfach nur vergessen haben, geben Sie das Protokoll, so dass anstelle von
smtp.gmail.com
ich musstessl://smtp.gmail.com
.InformationsquelleAutor der Antwort dav