Envoi Mail Excel et Thunderbird

nicomaiden

XLDnaute Nouveau
Bonjour,
Après avoir lu, relu, fouillé et creusé le forum, je me décide de poster.
Voilà comme pas mal de monde je cherche à envoyer un mail automatique si des dates d'échéances sont dépassées. Le programme ci après (que j'ai totalement pompé sur un site - Ron's Excel page) fonctionne avec outlook. Mon problème est que j'utilise Thunderbird au boulot et que je suis une bille en vba.
Donc je joins le code en espérant qu'on vienne me sauver !! :p

Sub TestFile_2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "L").Value) = "yes" _
And LCase(Cells(cell.Row, "M").Value) <> "send" Then

Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date."

.Send
End With
On Error GoTo 0
Cells(cell.Row, "M").Value = "send"
Set OutMail = Nothing
End If
Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub


Merci beaucoup de votre réponse
 

Guiv

XLDnaute Occasionnel
Re : Envoi Mail Excel et Thunderbird

Bonjour nicomaiden,
Apparemment, il y aurait une solution ICI, mais je n'ai pas approfondi (trouvé par une petite recherche sur le web)
Sinon, il y a la méthode CDO qui n'utilise pas le client de messagerie et donc fonctionne avec tous. Tu trouveras des exemples sur le forum.
Cordialement,
Guiv
 

Guiv

XLDnaute Occasionnel
Re : Envoi Mail Excel et Thunderbird

Re,
Un exemple en CDO (par le même Ron)
Code:
Sub MailCDO()
    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "TonServeurSmpt" 'à adapter
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With

    
                Set iMsg = CreateObject("CDO.Message")
                With iMsg
                    Set .Configuration = iConf
                    .To = cell.Value
                    .From = """MaPomme"" <mapomme@chose.fr>" 'ton adresse à adapter
                    .Subject = "MonSujet" 'à adapter
                    .TextBody = "Ceci est un message" 'à adapter
                    .Send
                End With
                Set iMsg = Nothing


    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub

Tu peux évidemment référer les adresses, corps de message, sujet etc à des cellules.
Cordialement,
Guiv
 

nicomaiden

XLDnaute Nouveau
Re : Envoi Mail Excel et Thunderbird

Super ça marche.
Par contre comment j'intègre ça cette partie dedans ?

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstant s)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "L").Value) = "yes" _
And LCase(Cells(cell.Row, "M").Value) <> "send" Then


dur dur... :confused:
 

Guiv

XLDnaute Occasionnel
Re : Envoi Mail Excel et Thunderbird

Re,
Je n'avais pas bien lu ton premier post. En fait, voilà la macro originale de Ron De Bruin :
Code:
Sub CDOMail()
    Dim iMsg As Object
    Dim iConf As Object
    Dim cell As Range
    Dim Flds As Variant

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "TonServeurSmpt" 'à adapter
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With

    For Each cell In Sheets("Feuil1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Offset(0, -1).Value <> "" Then
            If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "oui" Then
                Set iMsg = CreateObject("CDO.Message")
                With iMsg
                    Set .Configuration = iConf
                    .To = cell.Value
                    .From = """MaPomme"" <mapomme@chose.fr>" 'à adapter
                    .Subject = "MonSujet" 'à adapter
                    .TextBody = "Cher " & cell.Offset(0, -1).Value & vbNewLine & vbNewLine & _
                                "Ceci est un message pour vous" 'à adapter
                    .Send
                End With
                Set iMsg = Nothing
            End If
        End If
    Next cell

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub
Je pense qu'avec ça, tu peux adapter à ton fichier.
Bonne soirée.
Guiv
 

nicomaiden

XLDnaute Nouveau
Re : Envoi Mail Excel et Thunderbird

Hello
merci beaucoup !
Avec les autres infos que j'ai pu trouver, j'ai réussi un envoyer un mail.
Il me reste plus qu'à trouver comment envoyer le contenu d'une cellule dans le corps du message selon un critère.

++
 

Statistiques des forums

Discussions
312 299
Messages
2 086 987
Membres
103 419
dernier inscrit
mk29