Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: attach file to email  (Read 2818 times)

0 Members and 1 Guest are viewing this topic.

BM

    Topic Starter


    Rookie

    attach file to email
    « on: February 18, 2010, 03:56:45 AM »
    Hi,

    how can I attach file to email through cmd?

    I want to create a batch file that when I click on it, it will open new email (from active outlook email), attach file in specified path to that email and fill "to" and "subject" fields. So if I want to email that file I should only run batch file then click send. Is this doable?

    gpl



      Apprentice
    • Thanked: 27
      Re: attach file to email
      « Reply #1 on: February 18, 2010, 06:06:59 AM »
      this cannot be done natively with the commandline, a little vbscript would be able to assist you.

      Otherwise, if you really must use the commandline check this thread http://www.computerhope.com/forum/index.php?topic=64216.0

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: attach file to email
      « Reply #2 on: February 18, 2010, 06:53:58 AM »
      This little snippet may help:

      Code: [Select]
      Set ol = CreateObject("Outlook.Application")
      Set objNamespace =ol.GetNamespace("MAPI")
      Set objMailItem = ol.CreateItem(olMailItem)

      strRecipients  = "email of recipient(s)"
      objMailItem.Recipients.Add strRecipients
      objMailItem.Subject = "Attachment Enclosed"
      objMailItem.Body = "Hi"
      objMailItem.Attachments.Add "file to attach"
      objMailItem.Send
      ol.Quit

      Fill in strRecipients, subject, body, and attachments (use full path) with relevant data and you should be good to go.

      Save the script with a VBS extension and run from either the run box or the command line as wscript scriptname.vbs

      Good luck.  8)
      « Last Edit: February 18, 2010, 07:14:47 AM by Sidewinder »
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein