VB and VBA Users Source Code: Send a text email using the MS MAPI control
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Send a text email using the MS MAPI control
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, January 04, 2001
Hits:
1176
Category:
Visual Basic General
Article:
The following code sends an email using a MAPI client. You must first reference the "Microsoft MAPI Controls 6.0" and add both the "MAPI Messages" and "MAPI Session" controls to a form. 'Purpose : Send an plain text Email 'Inputs : sSendTo The email address of the recipient of the mail ' sSubject The subject/title of the mail ' sText The mail content ' [sAttachFile] Optional file to attach with the email. 'Outputs : Returns True if successful 'Author : Andrew Baker 'Date : 04/01/2001 17:03 'Notes : First reference then add both the MS MAPI Components to a form ' In VBA, right click the "Toolbox" dialog then select "addition controls" 'Revisions : 'Assumptions : Function MailSend(sSendTo As String, sSubject As String, sText As String, Optional sAttachFile As String) As Boolean On Error GoTo ErrHandler With MAPISession1 If .SessionID = 0 Then .DownLoadMail = False .LogonUI = True .SignOn .NewSession = True MAPIMessages1.SessionID = .SessionID End If End With With MAPIMessages1 .Compose .RecipAddress = sSendTo .AddressResolveUI = True .ResolveName .MsgSubject = sSubject .MsgNoteText = sText If Len(sAttachFile) > 0 And Len(Dir$(sAttachFile)) > 0 Then .AttachmentPathName = sAttachFile Else .AttachmentCount = 0 End If .Send False End With MailSend = True Exit Function ErrHandler: Debug.Print Err.Description MailSend = False End Function 'Demonstration routine Sub Test() MailSend "webmaster@vbusers.com", "MAPI Test", "Test Message!" MailSend "admin@vbusers.com", "MAPI Test", "Test Message!" End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder