erreur envoi smtp

erreur envoi smtp - ASP - Programmation

Marsh Posté le 31-10-2007 à 00:38:56    

j'ai une erreur smtp lorsque j'envoie mon body avec une page html.
attention si je met pas la valeur var ça marche
alors que quand je debugue et que je regarde la variable au format html ça à l'ai correct si quelqu'u à une idée
 
Imports System.Net.Sockets
Imports System.IO
Imports System.web.Mail
Partial Class mail2
    Inherits System.Web.UI.Page
 
    Public Function RecupHTTP(ByVal URL As String) As String
        ' Déclaration des variables
        Dim LeDomaine As Integer
        Dim LeURL As String = ""
        Dim LeHost As String = ""
        Dim LeChemin As String = ""
        Dim Resultat As String = ""
        Dim RecupHTTPChaine As String = ""
        Dim WebClient As New TcpClient()
        Dim WebStream As NetworkStream
        Dim WebWriter As StreamWriter
        Dim WebReader As StreamReader
        ' On découpe l'url envoyée en paramètre à la fonction
        LeDomaine = InStr(UCase(URL), "HTTP://" )
        If LeDomaine > 0 Then
            LeURL = Mid(URL, LeDomaine + 7)
        Else
            LeURL = URL
        End If
        LeDomaine = InStr(LeURL, "/" )
        If LeDomaine > 0 Then
            LeHost = Mid(LeURL, 1, LeDomaine - 1)
            LeChemin = Mid(LeURL, LeDomaine)
        Else
            LeHost = LeURL
            LeChemin = "/"
        End If
        ' On construit notre requete HTTP
        RecupHTTPChaine = "GET " & LeChemin & " HTTP/1.1" & vbCrLf & "Host: " & LeHost & vbCrLf & "Connection: Close" & vbCrLf & vbCrLf
        ' On ouvre une socket sur le port 90
        WebClient.Connect(LeHost, 90)
        WebStream = WebClient.GetStream
        WebWriter = New StreamWriter(WebStream)
        WebWriter.Write(RecupHTTPChaine)
        WebWriter.Flush()
        WebReader = New StreamReader(WebStream)
        ' On stock la page html dans notre variable "Resultat"
        Resultat = WebReader.ReadToEnd()
        ' On ferme la socket
        WebStream.Close()
        WebClient.Close()
        ' On renvoi ce que l'on a récupéré
        RecupHTTP = Resultat
    End Function
 
    Protected Sub btenvoyer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btenvoyer.Click
        Dim var = RecupHTTP("http://192.168.103.228" )
        Dim email As New MailMessage()
        email.From = tbExpediteur.Text
        email.To = tbDestinataire.Text
        email.Subject = tbObjet.Text
        email.BodyFormat = MailFormat.Html
        email.Body = "<html>" & _
"<head>" & _
"<meta http-equiv=""Content-Language"" content=""fr"">" & _
"<meta http-equiv=""Content-Type"" content=""text/html; charset=windows-1252"">" & _
"</head>" & _
"<body>" & _
"<p>Mon premier mail au format HTML</p>" & _
var & _
"</body>" & _
"</html>"
 
        SmtpMail.SmtpServer = "mail.sudouest.com"
        Try
            SmtpMail.Send(email)
        Catch ex As Exception
            lblerreur.Text = ex.Message
        End Try
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tbExpediteur.Text = "monmail"
        tbDestinataire.Text = "monmail"
        tbObjet.Text = "Mail Automatique : Ne pas répondre ! "
    End Sub
End Class

Reply

Marsh Posté le 31-10-2007 à 00:38:56   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed