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

Author Topic: Send file as an attachment from the command line  (Read 4736 times)

0 Members and 1 Guest are viewing this topic.

stanger1

  • Guest
Send file as an attachment from the command line
« on: November 09, 2005, 08:41:00 AM »
Is there any way to send an email attachment from the command line?  I have tried Blat and have used it on our LAN but it dies during dial up connection for our remote clients.  There must be a way to send an email attachment from the command line by using vbscript or jscript.  Any help with this would be greatly appreciated.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Send file as an attachment from the command li
« Reply #1 on: November 09, 2005, 03:23:11 PM »
Code: [Select]

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "FromAddress"
objEmail.To = "ToAddress"
objEmail.Subject = "Subject"
objEmail.Textbody = "Body"
objEmail.HTMLBody= "HTML Code Goes Here"
objEmail.AddAttachment "FileName Goes Here"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTPServerName"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


All fields must be quoted. Change From & To Address, Body and Subject; HTMLBody parameter is optional, delete if not needed; AddAttachment is name of file to attach; SMTPServerName is your mail server, check with ISP if necessary. The rest of the parameters should not be changed.

Save script with a vbs extension and run as:

cscript scriptname.vbs

Good luck.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

stanger12

  • Guest
Re: Send file as an attachment from the command li
« Reply #2 on: November 15, 2005, 02:29:36 PM »
Thanks for the reply.  I am getting the following error:  The transport failed to connect to the server.  
My SMTP Server requires authentication - I think this why I received the error.  How would I code this information.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Send file as an attachment from the command li
« Reply #3 on: November 15, 2005, 05:18:01 PM »
Are you using your network server for mail or a web server? If your ISP needs credentials, you may not want to script this, since everything sent out is text. On the other hand, if you need to send data to a secure page (better security), you would need to know the form name, the id and password field names in order to script your browser prior to sending the email.

I'm a little suprised since ISP mail servers rarely ask for credentials when sending mail. Tells us more about your mail server. Note: If you're using Outlook, you'd need to script Outlook for this, not the browser.

Let us know.  8)
« Last Edit: November 15, 2005, 05:20:10 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

stanger 1

  • Guest
Re: Send file as an attachment from the command li
« Reply #4 on: November 16, 2005, 07:51:45 AM »
Thanks for the reply.
Our email server is a network smtp server. It is a secure server and requires authentication so we have to enter a userid and password.  We use Outlook Express to send and receive our email, but we can log in through the web and retrieve it as well.  I have tried Blat to send email from the command line - it works great on our network.  However when I try to use it on dialup, it dies.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Send file as an attachment from the command li
« Reply #5 on: November 16, 2005, 11:10:32 AM »
To the script above you might try adding:

Code: [Select]
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ") = 0


AND/OR

Code: [Select]

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60


which will turn off any authentication and/or increase the timeout value.

The best I could find on BLAT was to use -ti 90 on the command line. Presumably this increases the time out value.

This network mail server of yours wouldn't by any chance be Exchange?

Good luck. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

stanger1

  • Guest
Re: Send file as an attachment from the command li
« Reply #6 on: November 16, 2005, 03:55:44 PM »
Our E-mail software is WorldClient for MDaemon.  I have tried to utilize your suggestions and am still getting the same error.  I will try the suggestion for Blat and see if I can get it to work.