Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A e-mail question

Status
Not open for further replies.

mcallaghan

IS-IT--Management
Mar 22, 2005
43
US
I currently have a vbscript that has a attachement to it. What I am currently looking to do is be able to send a e-mail with the attachement in the body of the e-mail.
Example:
Lets say the the attachement sample.txt file just has the words test 123.
I want to be able to send the words test 123 which is in the sample.txt file into the body of the e-mail without going out and grabbing the attached file.

Dim OleMailMsg
Dim mDef_type
Dim mID
Dim mProj
Dim Def_type
Dim mAssigned
Dim session
Dim Asession

set out=WScript.CreateObject("Outlook.Application")
set mapi=out.GetNameSpace("MAPI")
set mail=out.CreateItem(0)
Set Asession =

'mail.Recipients.Add("test.com")
mail.Subject = "Checkin File Changes"
mail.Body = "Checkin Files that have been changed..."

////Dont want this line anymore
mail.Attachments.Add ("c:\file1.log")

I just want the contents of the file to be in my body
////////////////////////////////////////
mail.Send
 
Take a look at FileSystemObject (aka fso) and the ReadAll method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your help now building on that. How will I take the file in this script.

set fso = CreateObject("Scripting.FileSystemObject")
set fil = fso.getFile("c:\file1.log")
if fil.size > 0 then
set fs = fso.opentextfile("c:\file1.log")
f = fs.readall()
And be able to change the font. The lines line up in the file("c:\file1.log") but when I put the script and place it in my e-mail it doesnt. Is there a way I can change the font to couriar.

The file1.log
-------------[changed 1]---------------|--[changed to 1]---
fdgfgfdfgfewqwewq wewewe package+| wewewe p+
-|-

THe e-mail
-------------[changed 1]---------------|---[changed to 1]---
fdgfgfdfgfewqwewq wewewe package+| we wewewe p+
-|-
Isnt lined up correctly
 
You have to play with HTMLbody (instead of body) and the <PRE> tag.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Does anyone have sample code that will help me using the htmlbody so that it doesnt change the format of the attached file. Spaces where needed font being the same and so on. I want the e-mail that gets sent to look exactly like the attached file. Currently its not lining things up correctly.
 
And what have you so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This is what I got so far. Im uncertain what i should do from here to be honest.

Set out=WScript.CreateObject("Outlook.Application")
set mapi=out.GetNameSpace("MAPI")
set mail=out.CreateItem(0)

set fso = CreateObject("Scripting.FileSystemObject")
set fil = fso.getFile("c:\file1.log")
if fil.size > 0 then
set fs = fso.opentextfile("c:\file1.log")
f = fs.readall()
fs.close: set fs = nothing
else
f = "File was empty"
end if
set fil = nothing
set fso = nothing
' response.write f
'mail.Body = f
mail.HTMLBody = f
mail.Recipients.Add("test@test.com")
mail.Send

 
And what about something like this ?
mail.HTMLBody = "<HTML><BODY><PRE>" & f & "</PRE></BODY></HTML>"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It works in html format but its still not lining up as nicely as the attatched file. Can you think of anything else i can do.
Thanks for all you help. It is very much helpful so far.
 
Do you know HTML?

You might try thinking of this as a web page rather than as an email message.

It might help if you make a web page that displays the way you want and then work BACKWARDS from there... using the VBScript to output the desired HTML.

If you don't know HTML then maybe you can use MS FrontPage or even MS Word with the Save As Web Page feature to build the HTML for you. Beware though, using a program to automatically generate your HTML sometimes results in some very unfriendly HTML... ie: easy for the browser to read but hard for YOU to read!
 
IS there a way we can read through a file and set the font to a fix length font file. Like courier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top