[VB.NET 2005]Probleme envoi de mail
Bonjour
J'ai testé ce code VB.NET dans une page aspx et il marche, mais lorsque j'essaye de l'utiliser dans un projet "Application console" il ne marche plus.:cry:Je ne comprend pas il me renvoi "echec d'envoi du courrier 1"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Private Sub EnvoisMail(ByVal oMailAdresse As String, ByVal oMailDestinataire As String, ByVal oMailSujet As String, ByVal oMailTexte As String, ByVal oMailSMTP As String, ByVal oMailLogin As String, ByVal oMailPassword As String, Optional ByVal oMailFichier As String = Nothing)
Dim oMail As MailMessage
Dim oSmtp As SmtpClient
oMail = New MailMessage
With oMail
.From = New MailAddress(oMailAdresse)
.To.Add(oMailDestinataire)
.Subject = oMailSujet
.Body = oMailTexte
.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
.SubjectEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
If oMailFichier <> "" Then
.Attachments.Add(New Attachment(oMailFichier))
End If
End With
oSmtp = New SmtpClient
With oSmtp
.Host = oMailSMTP
.Credentials = New Net.NetworkCredential(oMailLogin, oMailPassword)
.EnableSsl = False
.Port = 25
End With
Try
oSmtp.Send(oMail)
Console.WriteLine("ok")
Catch ex As SmtpException
Console.WriteLine(ex.Message & 1)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub |
J'ai donc une "SmtpException"
merci