Created
July 9, 2012 10:05
-
-
Save elleryq/3075535 to your computer and use it in GitHub Desktop.
Mail via Outlook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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_send_to_kindle@kindle.com" ' change this... | |
MessageSubject = Filename | |
MessageBody = "Send " & Filename & " via Outlook+Calibre" | |
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 | |
End If | |
Set ol = Nothing | |
WScript.Echo "Mail successed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment