' http://www.rgagnon.com/wshdetails/wsh-0018.html
' http://www.rgagnon.com/wshdetails/wsh-0002.html
' http://www.bernhard-ehlers.de/projects/OutlookSecurity.html
' Get full filepath from 1st argument
Dim Full_Filename
Dim Filename
Set objArgs = WScript.Arguments
if WScript.Arguments.Count=0 then
WScript.Quit 1
end if
' WScript.Echo objArgs(0)
Full_Filename = objArgs(0)
' Parse to simple filename
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Full_Filename)
Filename = objFSO.GetFileName(objFile)
Set objFile = Nothing
Set objFSO = Nothing
' Start to mail
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
ToAddress = "your_user@your_domain.com" ' change this...
MessageSubject = Filename
MessageBody = "Send " & Filename & " via Outlook"
MessageAttachment = Full_Filename
Dim ol, ns, newMail
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Attachments.Add(MessageAttachment).Displayname = Filename
newMail.Send
WScript.Echo "Mail successed! " & Full_Filename
End If
Set ol = Nothing