Я пытаюсь отправить почту через следующий кодОтправка почты через Gmail, используя SMTP
КОД
Dim MyMailMessage As New MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("[email protected]")
'To is a collection of MailAddress types
MyMailMessage.To.Add("[email protected]")
MyMailMessage.Subject = "GMail Test"
MyMailMessage.Body = "This is the test text for Gmail email"
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 465
SMTPServer.Credentials = New System.Net.NetworkCredential("[email protected]", "*****")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
MessageBox.Show("Email Sent")
Catch ex As SmtpException
MessageBox.Show(ex.Message)
End Try
Однако этот код не работает я получаю следующие исключения:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in MailSender.exe
И, наконец, доставка сообщения не удалась.
Любая идея, почему она не работает?
Примечание: Я попытался SMTPServer.Port = 587 тоже, но до сих пор ее не работает
Посмотрите на внутреннее исключение - сообщите нам, что это такое. –
Какое исключение вы получаете? Что в вашем MessageBox? –
Ниже перечислены исключения, которые я мог видеть на выходе: 1) Первое событие исключения типа System.Net.Sockets.SocketException произошло в System.dll 2) Первое исключение исключения типа «System.Net.WebException» произошло в System.dll 3) Первое событие исключения типа «System.Net.WebException» произошло в System.dll 4) В System.dll появилось первое исключение типа «System.Net.Mail.SmtpException»). Первая возможность исключение типа «System.Net.Mail.SmtpException» произошло в MailSender.exe – Isentropic