Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Problem sending e-mail from script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,45028
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Problem sending e-mail from script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Problem sending e-mail from script - 3/27/2007 2:11:22 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Had an idea - it's a step in the right direction, but it doesn't work:

I used Join to join my array, and store it in a variable strAttach, using ; as a delimiter.  I then tried:

objMail.Attachments.add(strAttach)

But this tells me "file not found".

I'm not sure if the Attachments.Add bit let's me add more than 1 file at a time.

(in reply to markmcrobie)
 
 
Post #: 21
 
 RE: Problem sending e-mail from script - 3/27/2007 2:35:25 AM   
  ehvbs

 

Posts: 2064
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi markmcrobie,

as I don't know anything about Outlook, I can just speculate that you have
to call Attachments.Add for each file specification in your list.

Good luck!

ehvbs

(in reply to markmcrobie)
 
 
Post #: 22
 
 RE: Problem sending e-mail from script - 3/27/2007 2:38:32 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
I've sussed out that you're right, I need a separate line/entry for each attachment.  In other words:

   objMail.Attachments.Add("C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 6.tif")
   objMail.Attachments.Add("C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 7.tif")

works fine, as does:

   objMail.Attachments.Add("C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 6.tif") : objMail.Attachments.Add("C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 7.tif")

whereas:

   objMail.Attachments.Add("C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 6.tif";"C:\Documents and Settings\mark.mcrobie\Desktop\Navynet\PSRC 7.tif")

doesn't work.

My problem is how do I get it to call a separate objMail.Attachments.Add for each entry in my array?

(in reply to ehvbs)
 
 
Post #: 23
 
 RE: Problem sending e-mail from script - 3/27/2007 2:41:20 AM   
  ehvbs

 

Posts: 2064
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Like:

For Each sFSpec In arrFiles
   objMail.Attachments.Add sFSpec  ' yes, no () here
Next

(in reply to markmcrobie)
 
 
Post #: 24
 
 RE: Problem sending e-mail from script - 3/27/2007 2:59:53 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Not sure what you mean?

(in reply to ehvbs)
 
 
Post #: 25
 
 RE: Problem sending e-mail from script - 3/27/2007 3:07:43 AM   
  ehvbs

 

Posts: 2064
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Beware: untested code from Outlook ignoramus:

Instead of

   objMail.Subject = "Transfer to Navynet" 
   objMail.Attachments.add("C:\test.txt")
   objMail.Body = "The attached files are to be placed onto the Navynet PC"
  
I'd try

   objMail.Subject = "Transfer to Navynet" 
   For Each sFSpec In arrFiles*
         objMail.Attachments.Add sFSpec  ' yes, no () here
  Next
   objMail.Body = "The attached files are to be placed onto the Navynet PC"
  
* this is the array you mentioned in

  My problem is how do I get it to call a separate objMail.Attachments.Add for each entry in my array?

  I used Join to join my array, and store it in a variable strAttach, using ; as a delimiter.

(in reply to markmcrobie)
 
 
Post #: 26
 
 RE: Problem sending e-mail from script - 3/27/2007 6:37:06 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Thanks for the pointer - after some messing about, the following works perfectly:

For Each strAttach In arrFiles
    objMail.Attachments.Add objPath & "\" & strAttach
Next

My next question is as the block of code for the e-mailing part is in a Sub, how do I call the Sub from elsewhere? (sounds a basic question, I know, but I have no experience of Subs and Functions)

Thanks

(in reply to ehvbs)
 
 
Post #: 27
 
 RE: Problem sending e-mail from script - 3/27/2007 6:55:59 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Ok, I sussed out how to call the Sub, was pretty easy.

So now I have code that says:

intSize = objFolder2.Size
If intSize < 5000000 Then SendAttach

Where objFolder2 is the folder where the renamed files are, and SendAttach is the name of my Sub.  My sub looks like:

Sub SendAttach()
   Dim objOutlook
   Dim objMail
   Dim strMsg
   Const olMailItem = 0
   Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(olMailItem)
   objMail.To = "mark.mcrobie@amec.com"
   objMail.Subject = "Transfer to Navynet" 
   For Each strAttach In arrFiles
       objMail.Attachments.Add objPath & "\" & strAttach
   Next
   objMail.Body = "The attached files are to be placed onto the Navynet PC"
   objMail.Display 'Use objMail.Display to display before sending, otherwise call objMail.Send to send without reviewing
   Set objMail = Nothing
   Set objOutlook = Nothing
End Sub

My problem now, in case you haven't spotted it, is my size comparison compares the total size of the files in the folder against 5MB, but my Sub only attaches the files who's names are in the array.

This means that if I run the script and it renames, say, 2 files at 100Kb each, but there's already, say, 6MB of files in the folder, then the Sub won't be called and these 2 won't be sent.

What I really need to do is compare the size of the files who's names are in the array against 5MB, and if it's less then call the Sub.

But I'm guessing I can't just get the size of the files from the looking at the size of the array, since it's the actual file size I need and the array basically just holds the name?

(in reply to markmcrobie)
 
 
Post #: 28
 
 RE: Problem sending e-mail from script - 3/27/2007 7:43:52 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Right, I thought about it and decided that if a user is going to want to e-mail the files, he/she is going to want to e-mail ALL the files in the folder, not just the ones that were renamed during the most recent run of the script.

So I wrote the following code:

Dim arrFileList()
Dim filecount
Dim filelist
Dim intArrCount2
Set filelist = objFolder2.Files
filecount = filelist.Count
ReDim arrFileList(filecount - 1)
For Each File In fso.GetFolder(objPath).Files
arrFileList(intArrCount2) = File.Name
intArrCount2 = intArrCount2 + 1
Next

Which will get all the file names from the folder (not just the ones renamed this time round), and store them in an array.  Then in my Sub I simply use the array above, and not the one from earlier which only has the names from the most recent run of the script.

I thought I'd be clever and try teach myself about Functions at the same time, and stick the block of code in a Function.  But if I do THAT, I have no idea how/where to call the Function.

(in reply to markmcrobie)
 
 
Post #: 29
 
 RE: Problem sending e-mail from script - 3/28/2007 12:27:29 AM   
  dm_4ever


Posts: 2396
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
You might be able to do something like this:


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to markmcrobie)
 
 
Post #: 30
 
 RE: Problem sending e-mail from script - 4/2/2007 1:23:55 PM   
  FBSmith

 

Posts: 4
Score: 0
Joined: 3/19/2007
Status: offline
The following e-mail code was copy & pasted from others, sorry about the no commenting.
But it does work for me.

What I would like is to schedule it to run on start up, but to only send if the IP has changed, but thats for someone way more clever than me.




Option Explicit

On Error Resume Next

Const cstrShowMyIP = "http://www.showmyip.com/xml/"

Dim objRemXML
Dim objMyIP
Dim strIPAddress

Set objRemXML = CreateObject("Microsoft.XMLDOM")
objRemXML.async = False
objRemXML.load(cstrShowMyIP)
If Err.Number <> 0 Then
  WScript.Echo "Error getting IP address from " & cstrShowMyIP
  WScript.Quit
End If

' Get our IP address
Set objMyIP = objRemXML.selectSingleNode("/ip_address/ip")
If Err.Number <> 0 Then
  WScript.Echo "Error getting IP address from XML data"
  WScript.Quit
Else
  strIPAddress = objMyIP.text
End If

Dim iMsg
Dim iConf
Dim Flds
Const cdoSendUsingPort = 2
Const strSmartHost = "SMTP.telus.net"

'Create the message object
   Set iMsg = CreateObject("CDO.Message")

'Create the configuration object
   Set iConf = iMsg.Configuration

'Set the fields of the configuration object to send using SMTP via port 25.

   With iConf.Fields 
       .item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
       .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost      
       .Update
   End With

'Set the message to,from,subject,body properties.
   With iMsg      
       .To = "someone@somewhere.com"
       .From = "me@somewhere.net"      
       .Subject = "IP address : " & strIPAddress  
       .TextBody = "Home IP address : " & strIPAddress    
       .Send   
   End With
set iMsg = Nothing
Set objMyIP = Nothing
Set objRemXML = Nothing

(in reply to dm_4ever)
 
 
Post #: 31
 
 RE: Problem sending e-mail from script - 4/2/2007 1:29:56 PM   
  dm_4ever


Posts: 2396
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Hi FBSmith,

Could you please create a new post for this so that others can provide assistance and not confuse this with the original?

< Message edited by dm_4ever -- 4/2/2007 2:05:10 PM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to FBSmith)
 
 
Post #: 32
 
 RE: Problem sending e-mail from script - 4/9/2007 12:48:59 PM   
  faulkkev

 

Posts: 137
Score: 0
Joined: 11/1/2005
Status: offline
you need to bounce it off a declared exchange server in your script.  Chances are your exchange will not relay outside your location but if you use the email name after the @ that matches the email of you company it should route internally.  I have done this before exchange will relay anything internally if it sees it's domain name for example our email is acme.com then the smtp script call will have to say anyname@acme.com but also specify the server by name.  Here is a sample note in capse where the exchange server is supposed to be named.  You can use any exchange server in your domain except maybe the front end.


Set objEmail = CreateObject("CDO.Message")
          objEmail.From = "admin1@acme.com"
          objEmail.To = johndoe@acme.com
          objEmail.Subject = "Spooler Service is down"
          objEmail.Textbody = "Spooler Service has entered a stopped state"
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
          "EXCHANGE SERVER NAME HERE"
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          objEmail.Configuration.Fields.Update
          objEmail.Send


(in reply to markmcrobie)
 
 
Post #: 33
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Problem sending e-mail from script Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts