Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2005, 04:07 PM
Friend of Wrox
Join Date: Jun 2003
Location: Arlington, TX, USA.
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default How do I attach a file to an email in my .vbs file

I am using the following code to send an email in this .vbs file:

set objMail = WScript.CreateObject("CDo.Message")

objMail.configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/SendUsing") = 2 ' using cdosendusingport
objMail.configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Mail.mycompany.org"
objMail.configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/SMTPServerPort") = 25
objMail.configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/SMTPAuthenticate") = 0 'cdoAnonymous

objMail.From = "DotNetTextFiles@mycompany.org"

strMailBody = "This Email Created/Sent: " & Now() & vbcrlf & vbcrlf

objmail.Subject = "A DotNet Application Error(s) Text File Created on " & strServerName

'***** DEV - EMAIL. *****
objmail.To = "melindasavoy@mycompany.org"

strMailBody = strMailBody & "A DotNet Application Error(s) Text File has been created on " & strServerName & " in:" & vbcrlf & vbcrlf
strMailBody = strMailBody & "X:\inetpub\logfiles\dotneterrors" & strDate & ".txt" & vbcrlf & vbcrlf
objmail.textbody = strMailBody

I need a way to attach the file that is in X:\inetpub\logfiles\dotneterrors.txt

Any direction or resource or help that anyone can provide would be appreciated. I've been looking this afternoon but to no avail.

Thank you.
Reply With Quote
  #2 (permalink)  
Old March 1st, 2005, 11:40 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

never used it myself, but here's an example from MSDN (iMsg is a CDO.Message object):

Dim iBp
Set iBp = iMsg.AddAttachment("http://example.microsoft.com")
Set iBp = iMsg.AddAttachment("c:\myfiles\file.doc")
' ..

Reply With Quote
  #3 (permalink)  
Old July 1st, 2011, 03:51 PM
Registered User
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi!Pgtips,I 'm sorry to doubt your reply. But I am afraid that you misunderstood the meaning of "imsg"."imsg" is not a method or prorerty of the cdo.message object,but ".AddAttachment" is one method of the cdo.message object,just like ".from" or ".to" in the code。Before you use "imsg",you have to "set imsg=createobject("cdo.message")".UNDERSTAND ME ?
Reply With Quote
  #4 (permalink)  
Old July 2nd, 2011, 08:02 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi there,

First of all, this thread is over 6 years old, so there really isn't much point in reopening it.

Secondly, yes, he understood you as he wrote:

(iMsg is a CDO.Message object):
Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
attach a file and save it in the databas mary25dec Pro JSP 1 December 11th, 2006 04:10 AM
Question on .vbs file savoym VBScript 2 February 24th, 2005 12:12 PM
Scheduling VBS file madhukp VBScript 1 September 22nd, 2004 07:14 AM
HELP with .VBS file savoym VBScript 1 July 31st, 2003 08:39 PM

All times are GMT -4. The time now is 07:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.