'Mail to me' for Outlook clients

The next VBscript sends a file from the command line or dragged to the shortcut of this script to your Outlook email account:

if wscript.arguments.count<>1 then wscript.quit


set fso=CreateObject("scripting.filesystemobject")
if not fso.FileExists(AttachmentName) then wscript.quit

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.To = "{here the email address to send to@email.nn}"
objMail.Subject = "Received attachement"
objMail.Body = "Attached file: """ & fso.GetFileName(AttachmentName) & """"
if Err=0 then MsgBox "Successfully sent: "& vbCrLF & "- """ &
fso.GetFileName(AttachmentName) & """"

See also this post.


Holy sh*t!

From the Intel (McAfee) Privacy Notice of True Key software (some kind of password manager):

Maybe NOT a good idea to use...


One-click send attachement to email

Yeah, yeah, VBscript is boo, boo and should be banned from the earth. However you can create and use handy scripts without 2 or more academic titles that you need for PowerShell programming or Visual Studio. Also this script does not require any .NET library or Visual Studio runtime installed. It should run from Windows 98 to Windows 10 (W7, W8.1 and W10 were tested).

Sometimes you need to send a file to your own email account. E.g. for the file to be used on another computer, Operating System of even Smartphone. Of course you can start your email program, create a new email to yourself, attach the file and send it. Easier would it be if you just can drag-and-drop the file on an application shortcut or use the Explorer context menu for that.

This post describes a script that using the Collaboration Data Object (CDO) and Gmail to send an attachment to your own email address. I suggest you create a new "" account for this purpose.

First the script. Edit the lines with your Gmail name, password and your own email address:

    Option Explicit
    dim arg,fso, i, s, objEmail, Subject

    set arg=WScript.Arguments
    set fso=CreateObject("scripting.filesystemobject")

    const GoogleAccount    = "{here your Gmail email name}"
    const GooglePassword   = "{here your Gmail email password}"
    const eMailTo          = "{here you own email address"

'--- Prepare email object variables...

    Set objEmail = CreateObject("CDO.Message")
 objEmail.Configuration.Fields.Item("")      = GoogleAccount

    objEmail.Configuration.Fields.Item("")      = GooglePassword
    objEmail.Configuration.Fields.Item("")        = ""
    objEmail.Configuration.Fields.Item("")        = 1
    objEmail.Configuration.Fields.Item("")  = 1
    objEmail.Configuration.Fields.Item("")         = 2
    objEmail.Configuration.Fields.Item("")    = 465

'--- Add attachement(s)...
    for i=0 to arg.count-1
        objEmail.AddAttachment arg.item(i)
        s=s & "- " & fso.GetFileName(arg.item(i)) & vbCrLf

'--- Alternative subject field?  
    Subject=InputBox("Enter subject","Alternative Subject","Attachement received " & s)
    if s="" then wscript.quit
'--- Populate other email fields...
    objEmail.From         = GoogleAccount
    objEmail.To           = eMailTo
    objEmail.Subject      = Subject
    objEmail.TextBody     = "Attached you find the next attachements: " & s

'---- Send the email...
    if Err=0 then
        MsgBox "Successful sent attachment(s): " & s
        MsgBox "Something went wrong sending attachment(s): " & s
    end if

You can use the script in different ways:
  1.     From the command line (nah...)
  2.     Drag-and-Drop a file to the shortcut of the script (nice)
  3.     With the Explorer context menu (best!)

Command line (assuming the script's name is SendAttachment-google.vbs and is in the c:\scripts folder):

    C:\> wscript c:\scripts\SendAttachment-google.vbs {path to whatever file you want to send}

Application shortcut:
Create a shortcut on the desktop to the  SendAttachment-google.vbs script. Maybe change the icon picture for better reading. Now just drag-and-drop the file you want to email to the icon.

Explorer context menu:
Create a registry file like this:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Send to email]
[HKEY_CLASSES_ROOT\*\shell\Send to email\command]
@="wscript c:\\scripts\\SendAttachement-google.vbs \"%1\""

Apply this file to the registry. Now you can right-click the file you want to email and select "Send to email":

A success/failure message is shown when done:

  •     There is almost no error checking in the script. Most common errors are:
    •  Wrong/typo in email address or password;
    • Sending a not-allowed file type through Gmail;
    • Wrong path of the script vs. configured path in shortcut or registry.
  •     The Gmail password is in clear text. To mitigate that you can encrypt the script to a VBE file with this method. Remember to change the references from VBS to VBE.
  •     Of course you can configure your own SMTP server. When using port 25 change also objEmail.Configuration.Fields.Item("") to 0.
  • You do not need some "Cloud Service" and client that is a available for a shorter or longer period or not available at all for your purpose.
  • You can send a maximum of 2000 emails per day, so spammers, go home!

Real Time Web Analytics