Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5 KiB

  1. Option Explicit
  2. 'global variables
  3. Dim Args ' Command line arguments object
  4. Dim objSession ' MAPI Session object
  5. Dim strProfileName ' Name of MAPI profile to use
  6. Dim strTo ' Recipient To field
  7. Dim strSubject ' Subject field
  8. Dim strMessageText ' Message body text
  9. Dim strAttachPath ' Full path of attachment file
  10. Dim I
  11. ' Parse command line arguments
  12. Set Args = Wscript.Arguments
  13. If Args.Count < 1 Then
  14. Wscript.Echo "Usage: CScript.exe " & Wscript.ScriptName & " /P <MAPI Profile> /R <Recipient> " & _
  15. "/S <Subject> /T <Text> /A <Attachment Path>"
  16. Wscript.Quit 1
  17. End If
  18. For I = 0 to Args.Count - 1 Step 2
  19. If UCase(Args.Item(I)) = "/P" Then strProfileName = Args.Item(I+1)
  20. If UCase(Args.Item(I)) = "/R" Then strTo = Args.Item(I+1)
  21. If UCase(Args.Item(I)) = "/S" Then strSubject = Args.Item(I+1)
  22. If UCase(Args.Item(I)) = "/T" Then strMessageText = Args.Item(I+1)
  23. If UCase(Args.Item(I)) = "/A" Then strAttachPath = Args.Item(I+1)
  24. Next
  25. Wscript.Echo "Profile: " & strProfileName
  26. Wscript.Echo "To: " & strTo
  27. Wscript.Echo "Subject: " & strSubject
  28. Wscript.Echo "Text: " & strMessageText
  29. Wscript.Echo "Attachment: " & strAttachPath
  30. Set objSession = CreateObject("MAPI.Session")
  31. If IsObject(objSession) Then
  32. objSession.Logon strProfileName, , False
  33. Dim objFolder
  34. Set objFolder = objSession.Outbox
  35. If IsObject(objFolder) Then
  36. Dim objMessages
  37. Set objMessages = objFolder.Messages
  38. If IsObject(objMessages) Then
  39. Dim objNewMessage
  40. Set objNewMessage = objMessages.Add
  41. If IsObject(objNewMessage) Then
  42. If strSubject <> "" Then
  43. objNewMessage.Subject = strSubject
  44. End If
  45. If strMessageText <> "" Then
  46. objNewMessage.Text = strMessageText
  47. End If
  48. If strAttachPath <> "" Then
  49. Dim objAttachments, strAttachName, nPos
  50. nPos = InStrRev(strAttachPath, "\")
  51. strAttachName = Mid(strAttachPath, nPos)
  52. Set objAttachments = objNewMessage.Attachments
  53. If IsObject(objAttachments) Then
  54. Dim objNewAttachment
  55. Set objNewAttachment = objAttachments.Add(strAttachName, 1, , strAttachPath)
  56. End If
  57. End If
  58. If strTo <> "" Then
  59. Dim objRecipients
  60. Set objRecipients = objNewMessage.Recipients
  61. If IsObject(objRecipients) Then
  62. objRecipients.AddMultiple strTo
  63. objRecipients.Resolve
  64. End If
  65. objNewMessage.Send False
  66. End If
  67. Wscript.Echo "It worked!"
  68. End If
  69. End If
  70. Set objMessages = Nothing'
  71. End If
  72. Set objFolder = Nothing
  73. objSession.Logoff()
  74. End If
  75. Set objSession = Nothing
  76. Wscript.Quit 0