Image dans un mail en VBA sans utiliser Outlook

Résolu
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   -  
 LEGONZ77 -
Bonjour,

Avant tout, je ne souhaite pas utiliser Outlook pour la génération des mails.

Voici mon code :

Sub EnvoiMail()

Dim mMessage As Object
Dim mConfig As Object
Dim mChps
Dim NOM_AFFRETEUR_MAIL As String
Dim ADRESSE_MAIL As String
Dim DF As Long
Dim DL_MAIL As Long
Dim DL_GENERAL As Long

    
'**********************************************************Pramétrage de gmail**********************************************************************************************
   
    Set mConfig = CreateObject("CDO.Configuration")
    
    mConfig.Load -1
    Set mChps = mConfig.Fields
    With mChps
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "1"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxxx@gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxx"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "true"
        .Update
    End With

DL_GENERAL = Sheets(2).Cells(Application.Rows.Count, 10).End(xlUp).Row

For k = 3 To DL_GENERAL

ADRESSE_MAIL = Sheets(2).Range("J" & k)
       
Set mMessage = CreateObject("CDO.Message")
            With mMessage
            Set .Configuration = mConfig
                .To = ADRESSE_MAIL
                .From = "xxxxxxx"
                .Subject = "INDEXATIONS GASOIL"
                .TextBody = "Vous trouverez en PJ les indexations gasoil pour tous les clients."
                .AddAttachment "K:\DEVELOPPEMENTS\TEMP\INDEXATIONS GASOIL GENERALES.pdf"
                .send
            End With
            Set mMessage = Nothing
            
Next k
    
     
Set mConfig = Nothing
Set mChps = Nothing
   
End Sub



Je souhaiterais ajouter une image à la fin du mail (une sorte de signature) mais je ne vois pas comment faire avec cette méthode. J'ai trouvé de nombreux renseignements à ce propos sur les divers forum mais par la méthode Outlook.

Je précise que j'ai posté ce message sur le forum excel-pratique mais le post est malheureusement resté sans réponse. Peut-être est-ce tout simplement impossible?

Merci d'avance pour votre aide.

Cordialement.
A voir également:

21 réponses

cs_Le Pivert Messages postés 7904 Date d'inscription   Statut Contributeur Dernière intervention   729
 
Chez moi en mettant Img = "Image.jpg" cela fonctionne très bien. Je ne comprends pas que cela ne marche pas chez toi!

Dans le post 3, j'ai cité ce site qui met effectivement derrière la variable Img le chemin entre parenthèse. Il faudrait peut-être approfondir la question

  & "<img src='cid:" & Trim(strFile) & "'" & "width='500' height='200'><br>" _


https://excel-macro.tutorialhorizon.com/excel-vba-send-unique-images-embedded-to-mail-body-with-every-mail-from-ms-outlook-using-excel/
0