Posted on Tuesday, January 18, 2011 12:47 PM
create form
Add button
Make a reference to microsoft scripting runtime
a
Public Function outlookMail(ByVal emailOntvanger As String, ByVal subject As String, ByVal body As String, ByVal bijlage As String) As Boolean
' extra:
' microsoft scripting runtime
' click yes (free software)
On Error GoTo errMsg
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = emailOntvanger
MessageSubject = subject
MessageBody = body
Set ol = CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "", "", True, False
Set newMail = ol.CreateItem(olMailItem)
newMail.subject = MessageSubject
newMail.body = MessageBody & vbCrLf
newMail.Attachments.Add (bijlage)
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add (myRecipient)
newMail.Send
End If
Set ol = Nothing
outlookMail = True
Exit Function
errMsg:
outlookMail = False
End Function