Advertisement
MrPav

VBA Code to Send Email

May 6th, 2015
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Sub Send_Email()
  2.  
  3. 'Open your default email profile
  4. Set objSession = CreateObject("mapi.session")
  5. objSession.Logon profileName:="Outlook" 'could be anything, open mail configuration program\mail in control panel
  6.  
  7. 'Add a new message object to the OutBox.
  8. Set objMessage = objSession.Outbox.Messages.Add
  9. 'subject and body
  10. objMessage.Subject = "Hey cool cat!"
  11. objMessage.Text = "Cats go Meow!"
  12.  
  13. 'Add recipient - email or username if using active directory
  14. Set objRecipient = objMessage.Recipients.Add
  15. objRecipient.Name = "Cats@Meow.purrrr.com"
  16. objRecipient.Type = 1
  17. objRecipient.Resolve
  18.  
  19. 'Send the message.
  20. objMessage.Send showDialog:=False
  21. 'Logoff using the session object.
  22. objSession.Logoff
  23.  
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement