Dit is de code die er in staat.
Option Explicit
Public PDF As String
Sub CDOmail(Blad As String, msgOnderwerp As String, Tekst As Range)
Dim iMsg As Object
Dim iConf As Object
Dim objImage As Object
Dim Flds As Variant
Dim Schema As String
Dim msgTekst As String
Dim SMTPsendusing As Integer
Dim SMTPauthenticate As Integer
Dim SMTPserver As String
Dim SMTPserverport As Integer
Dim SMTPusessl As Boolean
Dim SMTPusername As String
Dim SMTPpassword As String
Dim SMTPconnectiontimeout As Integer
ThisWorkbook.Activate
SMTPsendusing = Range("SMTPtype")
SMTPauthenticate = Range("SMTPauthenticate")
SMTPserver = Range("SMTPserver")
SMTPserverport = Range("SMTPport")
SMTPusessl = Range("SMTPusessl")
SMTPusername = Range("SMTPusername")
SMTPpassword = Range("SMTPpassword")
SMTPconnectiontimeout = Range("SMTPtimeout")
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Schema = "http://schemas.microsoft.com/cdo/configuration/"
iConf.Load -1 'zet CDO standaard instellingen
Set Flds = iConf.Fields
With Flds
.Item(Schema & "sendusing") = SMTPsendusing
.Item(Schema & "smtpauthenticate") = SMTPauthenticate
.Item(Schema & "smtpserver") = SMTPserver
.Item(Schema & "smtpserverport") = SMTPserverport 'Niet gebruiken bij Office365 SMTP
.Item(Schema & "smtpusessl") = SMTPusessl
.Item(Schema & "sendusername") = SMTPusername
.Item(Schema & "sendpassword") = SMTPpassword
.Item(Schema & "smtpconnectiontimeout") = SMTPconnectiontimeout
.Update
End With
msgTekst = RangeToHTML(Tekst)
With iMsg
.AutoGenerateTextBody = False
Set .Configuration = iConf
.To = HW.Sheets(Blad).Range("E13")
.CC = ""
.BCC = "nel_twigt@yahoo.com"
.From = SMTPusername
.Subject = msgOnderwerp
.HTMLBody = "<html><img src=""cid:LogoDistrict.gif""></html>" & msgTekst
Set objImage = iMsg.AddRelatedBodyPart(ThisWorkbook.Path & "\LogoDistrict.gif", "LogoDistrict.gif", 1)
objImage.Fields.Item("urn:schemas:mailheader:Content-ID") = "<LogoDistrict.gif>"
objImage.Fields.Update
.AddRelatedBodyPart ThisWorkbook.Path & "\LogoDistrict.gif", "LogoDistrict.gif", 1
.AddAttachment PDF
.Send
End With
If Err.Number <> 0 Then
MsgBox ActiveSheet.Name & vbCrLf & _
Err.Number & " - " & Err.Description, vbCritical, "Faktuur verzenden mislukt"
Else
MsgBox "De factuur is succesvol als PDF verzonden ! ", vbExclamation, "Bas Blok"
End If
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub