Email avec Winsock ?

pcpunch Messages postés 1243 Date d'inscription mardi 7 mai 2002 Statut Membre Dernière intervention 18 février 2019 - 30 janv. 2004 à 00:15
j2bond2 Messages postés 4 Date d'inscription lundi 18 août 2003 Statut Membre Dernière intervention 29 mai 2009 - 21 oct. 2004 à 11:02
Voila j'envoie un mail avec winsock jusque la pas de probléme, mais je voudrais attacher un fichier a mon mail.
On m'a donner une fonction pour encoder et envoyer le fichier :
Private Function UUEncodeFile(strFilePath As String) As String

Dim intFile As Integer 'file handler
Dim intTempFile As Integer 'temp file
Dim lFileSize As Long 'size of the file
Dim strFilename As String 'name of the file
Dim strFileData As String 'file data chunk
Dim lEncodedLines As Long 'number of encoded lines
Dim strTempLine As String 'temporary string
Dim i As Long 'loop counter
Dim j As Integer 'loop counter

Dim strResult As String
'
'Get file name
strFilename = Mid$(strFilePath, InStrRev(strFilePath, "") + 1)
'
'Insert first marker: "begin 664 ..."
strResult = "begin 664 " + strFilename + vbCrLf
'
'Get file size
lFileSize = FileLen(strFilePath)
lEncodedLines = lFileSize \ 45 + 1
'
'Prepare buffer to retrieve data from
'the file by 45 symbols chunks
strFileData = Space(45)
'
intFile = FreeFile
'
Open strFilePath For Binary As intFile
For i = 1 To lEncodedLines
'Read file data by 45-bytes cnunks
'
If i = lEncodedLines Then
'Last line of encoded data often is not
'equal to 45, therefore we need to change
'size of the buffer
strFileData = Space(lFileSize Mod 45)
End If
'Retrieve data chunk from file to the buffer
Get intFile, , strFileData
'Add first symbol to encoded string that informs
'about quantity of symbols in encoded string.
'More often "M" symbol is used.
strTempLine = Chr(Len(strFileData) + 32)
'
If i = lEncodedLines And (Len(strFileData) Mod 3) Then
'If the last line is processed and length of
'source data is not a number divisible by 3, add one or two
'blankspace symbols
strFileData = strFileData + Space(3 - (Len(strFileData) Mod 3))
End If

For j = 1 To Len(strFileData) Step 3
'Breake each 3 (8-bits) bytes to 4 (6-bits) bytes
'
'1 byte
strTempLine = strTempLine + Chr(Asc(Mid(strFileData, j, 1)) \ 4 + 32)
'2 byte
strTempLine = strTempLine + Chr((Asc(Mid(strFileData, j, 1)) Mod 4) * 16 + Asc(Mid(strFileData, j + 1, 1)) \ 16 + 32)
'3 byte
strTempLine = strTempLine + Chr((Asc(Mid(strFileData, j + 1, 1)) Mod 16) * 4 + Asc(Mid(strFileData, j + 2, 1)) \ 64 + 32)
'4 byte
strTempLine = strTempLine + Chr(Asc(Mid(strFileData, j + 2, 1)) Mod 64 + 32)
Next j
'replace " " with "`"
strTempLine = Replace(strTempLine, " ", "`")
'add encoded line to result buffer
strResult = strResult + strTempLine + vbCrLf
'reset line buffer
strTempLine = ""
Next i
Close intFile

'add the end marker
strResult = strResult & "`" & vbCrLf + "end" + vbCrLf
'asign return value
UUEncodeFile = strResult
End Function


Mais mon probléme reste le mm comment joindre ce fichier (On ma dit dans la parti data, mais j'ai essayer dans tous les sens!!! j'y arrive pas alors sii qq peu m'aider, voici un extrait de mon code, je suposse que c'est la que ca ce passe ??

Private Sub Winsock1_Connect()
Dim DataFile As String
DataFile = UUEncodeFile("C:\test.txt")
    ' La connection est etablie on envoie maintenant les données
    Dim Send(1 To 9) As String
    
    ' Les donnees a envoyer
    Send(1) = "HELO " & "smtp.wanadoo.fr" & vbCrLf
    Send(2) = "MAIL FROM:" & "<" & "jean-philippe@wanadoo.fr" & " > " & vbCrLf
    Send(3) = "RCPT TO:" & "<" & "pcpunch59@hotmail.com" & ">" & vbCrLf
    Send(4) = "DATA" & vbCrLf
    Send(5) = "from: " & Chr$(34) & "jean-philippe@wanadoo.fr" & Chr$(34) & "<" & "jeanphi" & ">" & vbCrLf
    Send(6) = "to: " & "<" & "pcpunch59@hotmail.com" & ">" & vbCrLf
    Send(7) = "subject: " & "Test messagerie" & vbCrLf & vbCrLf
    Send(8) = "Message" & vbCrLf & vbCrLf & "." & vbCrLf
    Send(9) = "QUIT"
    ' maintenant on les envoie en verifiant qu'il n'y a pas d'erreur
    On Error GoTo Erreur
    For x = 1 To 9
        Winsock1.SendData Send(x)
        Me.Print x
        DoEvents
    Next x
    Winsock1.Close
    MsgBox "Envoi effectué avec succès!"
    Exit Sub
Erreur: MsgBox "erreur"
    Exit Sub
End Sub

1 réponse

j2bond2 Messages postés 4 Date d'inscription lundi 18 août 2003 Statut Membre Dernière intervention 29 mai 2009
21 oct. 2004 à 11:02
salut
je suis entrain de faire le meme prog et je suis tombé sur ce site

http://grafikm.developpez.com/vbreseau/Lecon2Annexe1/

pour l'encodage.

j'espere que cela t'aidera, je te tient au courant si moi j'y arrive ;)

bye
0
Rejoignez-nous