2

I want to send email using outlook 2010, windows 7 & IE8 , what is code required to get the "Outlook.Application" object?.

I tried with CreateObject("Outlook.Application") but getting error "Object Required"

Vikas
  • 51
  • 1
  • 2
  • 7

4 Answers4

1

Try This simple code.

This will help you till opening the Outlook and navigate you to Inbox

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon "Default Outlook Profile", , False, True
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
objFolder.Display
End Sub
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
Ashwin
  • 245
  • 2
  • 7
  • 22
1

Sample Code :-

' Create email object
  Set oolApp = CreateObject("Outlook.Application")
  Set email = oolApp.CreateItem(0)
  email.Recipients.Add("abcaashn@gmail.com")

  ' Create the body of the email
  MailBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD W3 HTML//EN"">"
  MailBody = MailBody & "<HTML>" & vbcrlf
  MailBody = MailBody & "<HEAD><TITLE>No Invoices</TITLE></HEAD>"
  MailBody = MailBody & "<BODY>" & vbcrlf
  MailBody = MailBody & "<B>For Your Information</B>,<BR><BR>"
  MailBody = MailBody & "This is Sample Email.<BR><BR>"
  MailBody = MailBody & "</BODY></HTML>"

  ' Send the Email
  email.Subject = "No Invoices Issued"
  email.HTMLBody = MailBody
  email.Send
Amol Chavan
  • 3,835
  • 1
  • 21
  • 32
0

This will work for me:-

Public Sub runOutlook
 Set oolApp = CreateObject("Outlook.Application")
 Set objNS = oolApp.GetNamespace("MAPI")
 Set email = oolApp.CreateItem(0)
 email.Display
 email.To = "yash.tiwari@programmers.io"
 email.Subject = "Test"
 email.HTMLbody = "<b>For Your Information</b>, <br><br>" _
                    & "This is a Sample Email.<br><br>"              
 email.GetInspector.WindowState = 2             
End Sub
Shivam
  • 85
  • 8
0

You can send an email using CDO which is the subsystem that Outlook uses. You can find more information in my article Sending Emails Using CDO in WSH on ASP Free.

Set objMessage = CreateObject("CDO.Message")

' Set Email Headers
objMessage.From = "sender@mymail.com"
objMessage.To = "abcaashn@gmail.com"
objMessage.Subject = "No Invoices Issued"

' Construct Email Body
objMessage.HTMLbody = "<b>For Your Information</b>, <br><br>" _
                    & "This is a Sample Email.<br><br>"

objMessage.AutoGenerateTextBody = True

' Set Server Settings
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mymail.com"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Update
objEmail.Send
Nilpo
  • 4,675
  • 1
  • 25
  • 39