Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Sending E-Mails

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Sending E-Mails
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Sending E-Mails - 3/24/2007 7:56:09 AM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

I would like to have part of my script which would send an E-Mail to a specific recipient... but ONLY if a text file with a specific name, in a specific location is over 0K (I.E It has data in it) . I would like to have it write into a file that its going to send the error report off to servicedesk and then when its done it then it writes another line stating that its been successfully sent...

Would I be able to do this?  Where would I start?

Many Thanks

James
 
 
Post #: 1
 
 RE: Sending E-Mails - 3/24/2007 10:24:50 AM   
  dm_4ever


Posts: 2593
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
FileSystem object to check the file size and if it exists: http://msdn2.microsoft.com/en-us/library/z9ty6h50.aspx
CDO to send email: http://www.microsoft.com/technet/scriptcenter/scripts/message/smtpmail/mssmvb02.mspx

_____________________________

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 morpheus83uk)
 
 
Post #: 2
 
 RE: Sending E-Mails - 3/24/2007 10:54:46 AM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Thanks for the links

I will give them a go and get back to you guys if I am unsure of anything...

Cheers

James

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Sending E-Mails - 3/25/2007 9:32:31 AM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

How would I get the computers hostname into this E-Mail message and also the "Maintenance_Error_Log.txt" file attached to the mail?

Something else springs to mind... wouldnt XP automatically prompt you to ask if you want the "other program" to send the message on your belalf as it might thing its a virus?

Many Thanks

James

I have the following Code:


      

< Message edited by morpheus83uk -- 3/25/2007 9:36:18 AM >

(in reply to morpheus83uk)
 
 
Post #: 4
 
 RE: Sending E-Mails - 3/25/2007 6:57:58 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline

      

That's a basic template I use for any script that needs to send an email.  You can get the hostname by using the ComputerName method of the Network object

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 5
 
 RE: Sending E-Mails - 3/25/2007 9:13:04 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

Thanks for that...

I dont know what the port is for sending a mail... would it be 25? We are using EXCHANGE at work so I dont know if its any diffrent?? Would I be able to use the code without that part in?


      

So thyat looks ok? and would only send the attached file if it was equal to or over 1bytes?

Plus XP wouldnt winge about it seing sent? As I cant have it doing that as the user might have gone home when the script is running... Or would I need it to allow access for the program to send?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 6
 
 RE: Sending E-Mails - 3/25/2007 9:21:16 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
You don't need to know the port that's not what the cdosendUsingport setting means.  It just means, effectively, "send using the default SMTP port".  Leave it as 2.

XP shouldn't complain about it as you aren't using Outlook to send the file (whereas it might complain if you wrote a similar script in Outlook VBA).

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 7
 
 RE: Sending E-Mails - 3/25/2007 9:31:40 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Ohhh Right now I get you... I have uncommented that line...  :)

Cool so it will send a message to Servicedesk.....  Only when the maintenance_error_log.text is over 1 bytes... hurrah!

Is there a way it will capture the userID? so if JOE.BLOGGS was logged in then it would send the message from JOE.BLOGGS@STOCKPORT.GOV.UK?

Would it be able to do that?

Wat happens if the script would be run as an admin and not as the logged on user? would it use the admins name? opposed to the user who is using the PC?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 8
 
 RE: Sending E-Mails - 3/25/2007 9:56:54 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
To get the currently logged on username, use the UserName method of the network object.


      

or use AdSystemInfo


      

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 9
 
 RE: Sending E-Mails - 3/25/2007 10:46:27 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
So if we run the script as another user (The Administrator) would the script then say that the mail is off Administrator? Or the user who is logged into the session?

Many Thanks

James

P.S. Does this code look correct?


      

(in reply to ginolard)
 
 
Post #: 10
 
 RE: Sending E-Mails - 3/25/2007 11:02:14 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
It will take the lusername of the user running the script.  So if run as an Adminstrator, it would end up being adminstrator@stockport.gov.uk

However, there are some errors in your code.

.From = wscript.echo objNet.username & "@stockport.gov.uk"

should be

.From = objNet.username & "@stockport.gov.uk"


.TextBody = "Hostname: " & WshNetwork.ComputerName "This PC has Run Maintenance and created Errors. Please check the attached File."

should be


.TextBody = "Hostname: " & objNet.ComputerName & " This PC has Run Maintenance and created Errors. Please check the attached File." 

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 11
 
 RE: Sending E-Mails - 3/25/2007 11:10:45 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Cool thanks for that only minor things then :)

Could we make it get the username of the PC who is logged in rather than the user who is running the script?

If not then I can roll with Administrator Or even add a mail address called Maintenance_Admin@stockport.gov.uk if thats the case and send it as if it wee from that acount but it would be best if it come straight from the user? If thats at all possible?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 12
 
 RE: Sending E-Mails - 3/25/2007 11:14:56 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
quote:


Could we make it get the username of the PC who is logged in rather than the user who is running the script?


And so we touch upon one of the great problems of Vbscript.  Accurately obtaining the logged-on user ;) 

Yes, it's possible but it's not as obvious as you'd think.  You can query the owner of the explorer.exe process.  Seeing as explorer.exe only ever runs when a user is logged on it's 100% accurate.  Also, the owner of the process is the one who started it so it doesn't matter who is running the script.

This will also work for remote machines but I guess that's not needed here ;)


      

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 13
 
 RE: Sending E-Mails - 3/25/2007 11:27:28 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Thanks for that...

I have modified it... I am not sure if its correct or not...

The reason being is I dont need it to pop up a message box.. .


      

Would this be the correct script for what I need? Or have I just broke it even more?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 14
 
 RE: Sending E-Mails - 3/25/2007 11:39:00 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
Looks good to me ;)



_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 15
 
 RE: Sending E-Mails - 3/25/2007 11:47:11 PM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Thanks however I seem to get a syntex error on the following line:

colProc.Count > 0

Do you know why? Does it need the If and Then?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 16
 
 RE: Sending E-Mails - 3/25/2007 11:58:39 PM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
Oops, missed that yes.

If  colProc.Count > 0 Then
     For Each oProcess In colProc
         oProcess.GetOwner sUser, sDomain
         Exit For
      Next
End If

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 17
 
 RE: Sending E-Mails - 3/26/2007 12:08:26 AM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Superb thanks!!!

Well it seems to be happier with that!!

Thanks a lot!!!

Just one more thing to get sorted and that the error logging and were sorted!!! :)

Do you know anything about it?

Cheers

James

(in reply to ginolard)
 
 
Post #: 18
 
 RE: Sending E-Mails - 3/26/2007 12:19:52 AM   
  ginolard


Posts: 1044
Score: 21
Joined: 8/10/2005
Status: offline
Vbscript doesn't do error logging very well.

Basically, you need to put On Error Resume Next at the start of the script and, after every bit of code that MIGHT error out check the value of Err.Number

So, for example

ON Error Resume Next

'do some code that might error out

If Err.Number > 0 Then
   msgbox "There was an error"
End If

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to morpheus83uk)
 
 
Post #: 19
 
 RE: Sending E-Mails - 3/26/2007 12:49:53 AM   
  morpheus83uk

 

Posts: 320
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

this part of my code seems to run without checking the file size :(


      

So its writing the lines anyway rather than checking the size of the file... So if its 1Byte or more then it should write that on screen not just because it can...

Where have I gone wrong?

As for the error logging thing...

I have another post for that... its located http://wwww.visualbasicscript.com/m_43706/tm.htm

I have some idea of what I am doing but not loads...

In the other scripts I have put the code in there but your saying I need the On Error Resume Next In each script?

Many Thanks

James

(in reply to ginolard)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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 >> Sending E-Mails Page: [1] 2   next >   >>
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