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 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Imports System.Runtime.InteropServices*
Public Class Gmail
Implements IDisposable
' Field to handle multiple calls to Dispose gracefully.
Dim disposed As Boolean = False
' Implement IDisposable.
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposed = False Then
If disposing Then
' Free other state (managed objects).
disposed = True
End If
' Free your own state (unmanaged objects).
' Set large fields to null.
End If
End Sub
Protected Overrides Sub Finalize()
' Simply call Dispose(False).
Dispose(False)
End Sub
Public Sub MailEnvoi(Serveur, Identify, User, PassWord, Port, Delay, Expediteur, Dest, DestEnCopy, Objet, Body, Pj)
' sub pour envoyer les mails
Dim msg = Nothing
Dim Conf = Nothing
Dim Config = Nothing
Dim splitPj = Nothing
Dim IsplitPj = Nothing
msg = CreateObject("CDO.Message") 'pour la configuration du message
Conf = CreateObject("CDO.Configuration") ' pour la configuration de l'envoi
Config = Conf.Fields
' Configuration des parametres d'envoi
'(SMTP - Identification - SSL - Password - Nom Utilisateur - Adresse messagerie)
With Config
If Identify = True Then
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = User
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = PassWord
End If
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Serveur
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = Delay
.Update()
End With
'Configuration du message
'If E_mail.Sign.Value = Checked Then Convert ServeurFrm.SignTXT, ServeurFrm.Text1
With msg
.Configuration = Conf
.To = Dest
.cc = DestEnCopy
.FROM = Expediteur
.Subject = Objet
'
.HTMLBody = Body '"<p align=""center""><font face=""Verdana"" size=""1"" color=""#9224FF""><b><br><font face=""Comic Sans MS"" size=""5"" color=""#FF0000""></b><i>" & body & "</i></font> " 'E_mail.ZThtml.Text
If Pj <> "" Then
splitPj = Split(Pj & ";", ";")
For IsplitPj = 0 To UBound(splitPj)
If Trim("" & splitPj(IsplitPj)) <> "" Then
.AddAttachment(Trim("" & splitPj(IsplitPj)))
End If
Next
End If
.Send() 'envoi du message
End With
' reinitialisation des variables
msg = Nothing
Conf = Nothing
Config = Nothing
End Sub
Private Function GetObject(ByVal App As String) As Object
Try
Return Marshal.GetActiveObject(App)
Catch ex As Exception
Return CreateObject(App)
End Try
End Function
Private Function CreateObject(ByVal app As String) As Object
Dim AppType As Object = Type.GetTypeFromProgID(app)
Dim ApplInst As Object = Activator.CreateInstance(AppType)
Return ApplInst
End Function
End Class |