Freek's Blog

SQL en .NET vraagstukken en oplossingen die ik zoal tegenkom
posts - 199, comments - 123, trackbacks - 2, articles - 7

My Links

News

Google analytics script: Locations of visitors to this page

Article Categories

Archives

Post Categories

Image Galleries

Algemene links

MSDN

vb links

VB6: sending mail by outlook

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

 

Feedback

# re: VB6: sending mail by outlook

7/25/2011 5:22 AM by 数据恢复
THANKS

# replica sunglasses

4/1/2012 4:41 AM by replica sunglasses
a single flat fee, regardless of whether the filer's

Post Comment

Title  
Name  
Url
Comment   

ATTENTION: the code you need to copy is CaSe SeNsItIvE and is required to prevent spam.
Enter the code you see: