title: How does this script (sending email using Outlook) work?
body: <p>Can anyone help me understand how MAPI works? I have this simple vbscript that uses MAPI to send an email out. It works perfectly fine, but, I don't know how it is doing that...what's happening in the background?</p>
  
  <pre><code>Const ForReading = 1
  
  Set args = WScript.Arguments
  sqlFile = args.Item(0)
  logFile = args.Item(1)
  
  Dim ToAddress
  Dim FromAddress
  Dim MessageSubject
  Dim MyTime
  Dim MessageBody
  Dim MessageAttachment
  Dim ol, ns, newMail
  MyTime = Now
  
  ToAddress = "my@email.com"
  MessageSubject = "Subject goes here"
  MessageBody = "Body message goes here." 
  MessageAttachment = ""&amp;logFile&amp;""
  Set ol = WScript.CreateObject("Outlook.Application")
  Set ns = ol.getNamespace("MAPI")
  Set newMail = ol.CreateItem(olMailItem)
  newMail.Subject = MessageSubject
  newMail.Body = MessageBody &amp; vbCrLf &amp; MyTime
  newMail.RecipIents.Add(ToAddress)
  newMail.Attachments.Add(MessageAttachment)
  newMail.Send
  </code></pre>
  
  <p>Thanks in advance...</p>