Macro voor het mailen via gmail

Status
Niet open voor verdere reacties.

Joeri113

Gebruiker
Lid geworden
26 nov 2015
Berichten
7
Beste,

Ik ben bezig geweest met een maco voor het versturen van een mail via gmail.
Zo heb ik verschillende macro's van het internet gehaald en geprobeerd maar ik kom er niet uit.

Ik heb in vba onder verwijzingen Microsoft "CDO for Windows 2000 Library" aangevinkt.
Daarnaast heb ik in google de laagste veiligheid geaccepteerd.
Ten slotte heb ik niet alleen poort 25 maar ook poort 465 geprobeerd.

Waar gaat het mis bij de macro?
De code die ik nu heb staat hieronder.

Code:
Sub send_email_via_Gmail()
Dim myMail As CDO.Message

Set myMail = New CDO.Message

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "eigen mail adres"

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Wachtwoord"

myMail.Configuration.Fields.Update

With myMail
.Subject = "Test Email"
.From = "eigen mail adres"
.To = ""
.CC = ""
.BCC = ""
.TextBody = "Good morning!"
.AddAttachment ""
End With
On Error Resume Next
myMail.Send
'MsgBox ("Mail has been sent")
Set myMail = Nothing

End Sub
 
De code is goed, maar haal die On Error Resume Next eens weg. Die moet je alleen gebruiken voor het negeren van een bekende fout en niet zomaar willekeurig. Als er nu iets fout gaat zie je dat dus niet. Wellicht dat je een foutmelding ziet als je die regel weg haalt zodat je weet wat er aan de hand is.

Zorg er tevens voor dat je bij /sendusername je volledige GMail adres gebruikt, dus inclusief @gmail.com
 
Laatst bewerkt:
Bedankt voor de snelle reactie!

Ik heb het verwijderd en krijg nu de volgende melding: "Fout-2147220973 (80040213) tijdens uitvoering: De transportfunctie kan geen verbinding maken met de server."
 
Dan lijkt het erop dat in je firewall port 25 geblokkeert is.
 
Hiermee lukt het op mijn systeem

Code:
Sub M_snb_load()
    ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\cdosys.dll"
End Sub


Code:
Sub M_snb()
' wijzig de gegevens in de ***** gemarkeerde regels

  With New CDO.Message
    .Configuration(cdoSendUsingMethod) = 2
    .Configuration(cdoSMTPServer) = "smtp.gmail.com"
    .Configuration(cdoSMTPServerPort) = 465
    .Configuration(cdoSMTPUseSSL) = True
'   .Configuration(cdoSMTPConnectionTimeout) = 60
    .Configuration(cdoSMTPAuthenticate) = 1
    .Configuration(cdoSendUserName) = "xxx@gmail.com"                '   *******
    .Configuration(cdoSendPassword) = "yyyy"                         '    *******
    .Configuration.Fields.Update
        
'   .addattachment "G:\OF\bijlage.pdf"
    .From = "xxx@gmail.com"                                          '   *******
    .To = "xxx@gmail.com"                                            '   *******
    .Subject = "snb"
    .TextBody = "inhoud"
    .send
  End With
End Sub
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan