VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Send Mail from Visual Basic Using OLE Messaging

by C.J. (13 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 2nd October 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Send Mail from Visual Basic Using OLE Messaging

Rate Send Mail from Visual Basic Using OLE Messaging



' 2) On the Tools menu, choose References and select the Microsoft CDO 1.21 Library.
' 3) Add a CommandButton to the default form. Accept the default name, Command1.
' 4) Copy the following code into the General Declarations section of the default form:


Option Explicit


Private Sub Command1_Click()
  Dim objSession As Object
  Dim objMessage As Object
  Dim objRecipient As Object


  'Create the Session Object
  Set objSession = CreateObject("mapi.session")


  'Logon using the session object
  'Specify a valid profile name if you want to
  'Avoid the logon dialog box
  objSession.Logon profileName:="MS Exchange Settings"


  'Add a new message object to the OutBox
  Set objMessage = objSession.Outbox.Messages.Add


  'Set the properties of the message object
  objMessage.subject = "This is a test."
  objMessage.Text = "This is the message text."


  'Add a recipient object to the objMessage.Recipients collection
  Set objRecipient = objMessage.Recipients.Add


  'Set the properties of the recipient object
  objRecipient.Name = "John Doe"  '<---Replace this with a valid
                                  'display name or e-mail alias
  objRecipient.Type = mapiTo
  objRecipient.Resolve

  'Send the message
  objMessage.Send showDialog:=False
  MsgBox "Message sent successfully!"

  'Logoff using the session object
  objSession.Logoff
End Sub

Download this snippet    Add to My Saved Code

Send Mail from Visual Basic Using OLE Messaging Comments

No comments have been posted about Send Mail from Visual Basic Using OLE Messaging. Why not be the first to post a comment about Send Mail from Visual Basic Using OLE Messaging.

Post your comment

Subject:
Message:
0/1000 characters