Bonjour,

Je voudrais réaliser une application avec laquelle je puisse envoyer des mails avec fichiers attachés.

Donc j'ai essayé de passer par le serveur smtp de gmail (smtp.gmail.com, port 587).

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 Dim objMessage As System.Net.Mail.MailMessage
        Dim objAdrExp As System.Net.Mail.MailAddress
        Dim objAdrRec As System.Net.Mail.MailAddress
        Dim objSMTPClient As System.Net.Mail.SmtpClient
 
 
        Try
            objMessage = New System.Net.Mail.MailMessage()
 
            objAdrExp = New System.Net.Mail.MailAddress("neotof01@gmail.com")
 
            objAdrRec = New System.Net.Mail.MailAddress("neotof01@gmail.com")
 
            ' ADRESSE MAIL DE L EXPEDITEUR
            objMessage.From = objAdrExp
 
            ' ADRESSE MAIL DU DESTINATAIRE
            objMessage.To.Add(objAdrRec)
 
            objMessage.Subject = "Salut c VB.Net qui envoi ce mail"
            objMessage.IsBodyHtml = False
 
            objSMTPClient = New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
            objSMTPClient.EnableSsl = True
            objSMTPClient.Credentials = New NetworkCredential("neotof01@gmail.com", "xxxxx")
            objSMTPClient.Send(objMessage)
            MsgBox("Ok")
 
        Catch ex As Exception
            MsgBox("Exception : " & ex.Message)
        End Try
ou ça

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Private Sub EnvoiMail(ByVal De As String, ByVal Pass As String, ByVal Sujet As String, ByVal A As String, ByVal Message As String, ByVal attach As String)
 
        Dim TheServer As String = "smtp.gmail.com"
 
 
 
        Dim Smtp As New SmtpClient(TheServer, 587)
        Dim EmailMessage As New MailMessage()
        ' ERROR: Not supported in C#: WithStatement
 
        Try
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
 
        ' ERROR: Not supported in C#: WithStatement
 
        Try
        Catch ex As Exception
            MsgBox("Echec d'envoi du message!", MsgBoxStyle.Critical)
        End Try
 
 
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Call EnvoiMail("neotof01@gmail.com", "xxxxxx", "test sujet", "neotof01@gmail.com", "dsdsds", "")
    End Sub
D'avance merci