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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
Option Explicit On
Public Class Send_mail
'Déclaration de constantes
Const PourLecture = 1
Const cteAdresseSource = "dextre@dextre.com"
Dim sPieceJointe As String
Private Sub Envoyer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Envoyer.Click
' Déclaration de variables
'Dim ctl As Control
'Dim HasError As Boolean = False
'Dim Nom_champ As String
Dim index As Integer = 1
Dim objMail As Object
Dim sDestination As String = Tbdestinataire.Text
Dim msgTitre As String = Tbobjet.Text
Dim msgTexte As String = TextBox4.Text
Dim Drapeau As Boolean
If (index > 0) Then
objMail = CreateObject("CDO.Message")
Drapeau = False
'sDestination = "kevingoube@msn.com"
'msgTitre = "Automatisme"
'msgTexte = "Bonjour," & vbLf & "Corps du message"
'sPieceJointe = "Y:\Stagiaires\Développeurs\kgoubé\Mes documents\myfichier.txt"
Drapeau = True
With objMail
' Ligne à modifier selon l'adresse de l'envoyeur
.From = cteAdresseSource
.To = sDestination
.Subject = msgTitre
.TextBody = msgTexte
' Ligne à modifier selon le texte voulu !
'If (sPieceJointe <> "") Then
' If (Drapeau = True) Then
' .TextBody = msgTexte & vbLf & LirePieceJointe(sPieceJointe) & vbLf
' Else
' .TextBody = msgTexte & vbLf & "Pièce jointe incluse : " & vbLf
' End If
'Else
' .TextBody = msgTexte & vbCrLf & "Aucune Pièce jointe" & vbCrLf
'End If
' Ligne à modifier selon l'adresse du serveur SMTP
.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.orange.fr"
.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Update()
'If ((sPieceJointe <> "") And (Drapeau = False)) Then
' objMail.AddAttachment(sPieceJointe)
'End If
'For Each ctl In Me.Panel1.Controls
' If TypeOf ctl Is TextBox And ctl.Text.Length = 0 Then
' Nom_champ = ctl.Name
' Ep.SetError(ctl, "Le champ " & Nom_champ & " ne peut être vide !")
' HasError = True
' End If
'Next
'If HasError = True Then
' MsgBox("Tous les champs n'ont pas étaient rempli, Vérifiez que tous les champs soient remplis avant d'envoyer votre e-mail", MsgBoxStyle.Information, "Attention")
' Exit Sub
'End If
.Send()
End With
objMail = Nothing
MsgBox("Courriel envoyé !")
Else
Me.Close()
End If
Me.Close()
End Sub |
Partager