Solved

Embed file contents to body of CDO message

Posted on 2007-12-03
2
2,492 Views
Last Modified: 2010-08-05
I am using vbscript to send messages from Windows Server 2003.  All is well except that I cannot find a way to embed the contents of a text file into the message body.  It will work as an attachment, but that is not what Im looking for.  Heres the code:


Set objArgs = WScript.Arguments
 
Set objSendMail = CreateObject("CDO.Message")
Set network = CreateObject("wscript.network")
      
objSendMail.From = "Operating.System@mydomain.com"
objSendMail.To = objArgs(0)
objSendMail.Subject = network.computername & " : " & objArgs(1)
objSendMail.TextBody = objArgs(2)
objSendMail.AddAttachment objArgs(3) 'heres where I want to add the filepath
objSendMail.Send
         
Set objSendMail = Nothing			    
Set network = Nothing

Open in new window

0
Comment
Question by:BillPowell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
chandru_sol earned 500 total points
ID: 20400360
Try this.......

'These constants are defined to make the code more readable
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenTextFile("c:\temp\MyEmail.txt", ForReading)
'The ReadAll method reads the entire file into the variable BodyText
BodyText = f.ReadAll
'Close the file
f.Close
Set f = Nothing
Set fso = Nothing

this link will give you lots about CDO

http://www.paulsadowski.com/WSH/cdo.htm

regards
Chandru

Re
0
 

Expert Comment

by:PerceptiveSoftware
ID: 21693213
Chandru,

I have tried using that code before, and it will not include the contents of the file in my email body.  I've tried both HTML and Text, and neither work.  Any gotchas I should look for?  I've attached the part of my code that creates and sends the email.  I do get the emails, they're just blank.

Thanks
'These constants are defined to make the code more readable
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, BodyText
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenHTMLFile("c:\PasswordExpirationNotifier\PWD.html", ForReading)
'The ReadAll method reads the entire file into the variable BodyText
Set BodyText = f.ReadAll
'Close the file
f.Close
Set f = Nothing
Set fso = Nothing
 
Sub SendEmailMessage(strDestEmail, strNoOfDays)
  Set objMessage = CreateObject("CDO.Message")
  objMessage.Subject = "Password Expires in " & strNoOfDays & " days"
  objMessage.Sender = "administrator@mydomain.com"
  objMessage.To = "me@mydomain.com"
  objMessage.HTMLBody = BodyText
  objMessage.Send
End Sub

Open in new window

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Permission on folders 6 35
CSV file copy field 1 to field 2 2 63
what should i learn? javascript or typescript? 3 68
vb6 Where condition on dbo 2 31
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question