Newbie Emailing text file into body of Email 
Author Message
 Newbie Emailing text file into body of Email

I'm just learning about VBScript so please be gentle.  I have written the
following script:

' Emails text file quickly.

Option Explicit

Dim oFSO, oFile
Dim strFilename, strData
Dim emadd, emsub
Dim WshShell, oExec

Const ForReading = 1
Const ForWriting = 2

strFileName = "email.txt"

' Reads Email.txt for Body of Email message.
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(strFileName, ForReading)
strData = oFile.ReadAll
oFile.Close

emadd = InputBox("Type in email address")
emsub = InputBox("Type in subject")

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "mailto:" & emadd & "?subject=" & emsub & "&body=" & strData

    The problem comes at the very end.  The "mailto:" command can't have any
spaces in the command that is sent to the run method.  You can get around
that my enclosing quotes around two words or several words.
    My question is how would I do that for my variables.  Right now if the
Subject contains two words it opens a message window, but only the first
subject word is in the subject line, and no message body.  If the subject is
one word then it fail after the first word in the body.
    Is there a way I can work around this to use the mailto command.  I
would like to do it this way so I can add more addresses or add to the body
in the message window.

    Thank you for any help.

mowestusa



Wed, 10 Aug 2005 00:17:58 GMT  
 Newbie Emailing text file into body of Email


Quote:
> I'm just learning about VBScript so please be gentle.  I have written the
> following script:

> ' Emails text file quickly.

> Option Explicit

> Dim oFSO, oFile
> Dim strFilename, strData
> Dim emadd, emsub
> Dim WshShell, oExec

> Const ForReading = 1
> Const ForWriting = 2

> strFileName = "email.txt"

> ' Reads Email.txt for Body of Email message.
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oFile = oFSO.OpenTextFile(strFileName, ForReading)
> strData = oFile.ReadAll
> oFile.Close

> emadd = InputBox("Type in email address")
> emsub = InputBox("Type in subject")

> Set WshShell = CreateObject("WScript.Shell")
> WshShell.Run "mailto:" & emadd & "?subject=" & emsub & "&body=" & strData

>     The problem comes at the very end.  The "mailto:" command can't have
any
> spaces in the command that is sent to the run method.  You can get around
> that my enclosing quotes around two words or several words.
>     My question is how would I do that for my variables.  Right now if the
> Subject contains two words it opens a message window, but only the first
> subject word is in the subject line, and no message body.  If the subject
is
> one word then it fail after the first word in the body.
>     Is there a way I can work around this to use the mailto command.  I
> would like to do it this way so I can add more addresses or add to the
body
> in the message window.

>     Thank you for any help.

Maybe you should rethink what you're trying to do. The mailto command opens
their current email client with a new message with the stuff you've
specified, but you make them type in the email address and subject
beforehand anyway. Seeing as they'll have a chance to change those anyway
when they send a file, your script is kinda pointless. Maybe you should just
stick with the Send To menu or possibly drag the Mail Recipient icon from
the SentTo folder to the desktop so they can drag to it instead.


Wed, 10 Aug 2005 03:56:17 GMT  
 Newbie Emailing text file into body of Email
Quote:
> Maybe you should rethink what you're trying to do. The mailto command
opens
> their current email client with a new message with the stuff you've
> specified, but you make them type in the email address and subject
> beforehand anyway. Seeing as they'll have a chance to change those anyway
> when they send a file, your script is kinda pointless. Maybe you should
just
> stick with the Send To menu or possibly drag the Mail Recipient icon from
> the SentTo folder to the desktop so they can drag to it instead.

Good thoughts.

I really made this script for myself.  You make a good point about the other
very effective ways to send an email, and all of them are more efficent than
what I was trying to accomplish.  I'm writing this script as a learning
experience for VBscript.  I use Metapad as my default text editor.  It has
the interesting option of running external viewers and VBscripts can be run
as well.  Eventually I would like to build a VBscript that emails whatever
text file I am working on at the time by putting it into the body of an
email.  This will involve taking the text file name from the command line
argument which I haven't learned how to do yet.  This way instead of opening
up Outlook Express, copying, starting a new message, and then pasting the
text into the message body, this could be automated with a press of a
button.

Now I know that there is a way that you can start an Outlook Express message
without using the "mailto" command.  I wanted to use the mailto command
originally so that I could preview the message before it is just sent out in
the background to make sure that I put in the right email address and
things, but I didn't want to start up Outlook Express just to send off a
quick copy of the text document I was working on.  If anyone would like to
share with me a website that illustrates calling the Outlook Express Object
and the command line arguments I would appreciate it.  Whenever I do a
search on Google so much on VBscript is for ASP and webpage scripts.  I'm
more interested in using VBscript in place of batch files on my local
computer.

Thank you for help.

mowestusa



Thu, 11 Aug 2005 00:37:02 GMT  
 Newbie Emailing text file into body of Email
I have a script that I use for sending e-mail, it accepts command line
args for recipients, message body, and an optional attachment. I tried
to e-mail it to you but it failed. If you would like it, post a valid e-mail
address and I will bounce it your way. It uses CDO so it is only
supported on Win2K and beyond.

TDM


Quote:
> > Maybe you should rethink what you're trying to do. The mailto command
> opens
> > their current email client with a new message with the stuff you've
> > specified, but you make them type in the email address and subject
> > beforehand anyway. Seeing as they'll have a chance to change those
anyway
> > when they send a file, your script is kinda pointless. Maybe you should
> just
> > stick with the Send To menu or possibly drag the Mail Recipient icon
from
> > the SentTo folder to the desktop so they can drag to it instead.

> Good thoughts.

> I really made this script for myself.  You make a good point about the
other
> very effective ways to send an email, and all of them are more efficent
than
> what I was trying to accomplish.  I'm writing this script as a learning
> experience for VBscript.  I use Metapad as my default text editor.  It has
> the interesting option of running external viewers and VBscripts can be
run
> as well.  Eventually I would like to build a VBscript that emails whatever
> text file I am working on at the time by putting it into the body of an
> email.  This will involve taking the text file name from the command line
> argument which I haven't learned how to do yet.  This way instead of
opening
> up Outlook Express, copying, starting a new message, and then pasting the
> text into the message body, this could be automated with a press of a
> button.

> Now I know that there is a way that you can start an Outlook Express
message
> without using the "mailto" command.  I wanted to use the mailto command
> originally so that I could preview the message before it is just sent out
in
> the background to make sure that I put in the right email address and
> things, but I didn't want to start up Outlook Express just to send off a
> quick copy of the text document I was working on.  If anyone would like to
> share with me a website that illustrates calling the Outlook Express
Object
> and the command line arguments I would appreciate it.  Whenever I do a
> search on Google so much on VBscript is for ASP and webpage scripts.  I'm
> more interested in using VBscript in place of batch files on my local
> computer.

> Thank you for help.

> mowestusa



Mon, 15 Aug 2005 20:47:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Emailing a text file

2. IIS 5 and emailing the log files

3. IIS 5 and emailing the log files

4. Problem emailing from VB/Access when notes is email server

5. Emailing images using Files and Folder Tasks

6. Emailing Files from Access2000

7. Emailing a file from VB

8. Emailing using the default email client

9. IMP: Emailing Zipped Files ?

10. Emailing Files from Access2000

11. Inserting text to email body (not a signature)

12. Inserting text to email body

 

 
Powered by phpBB® Forum Software