Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 28th, 2005, 04:07 PM
Friend of Wrox
Join Date: Jun 2003
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 = "[email protected]"

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

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

'***** DEV - EMAIL. *****
objmail.To = "[email protected]"

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
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
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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

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

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