Visual Basic > Internet Web Mail Stuff
Send a text email using the MS MAPI control
Send a text email using the MS MAPI control 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 'Notes : First reference then add both the MS MAPI Components to a form ' In VBA, right click the "Toolbox" dialog then select "addition controls" 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@domain", "MAPI Test", "Test Message!" MailSend "admin@domain", "MAPI Test", "Test Message!" End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows