Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1083
  • Last Modified:

Sending emails from vbscipt - Office 2010

Does anyone know of a way to send emails from within a vbscript that does not rely on using CDO.   We have Windows XP Pro and Windows 7 Pro desktops running Office 2010 which does not include the Microsoft CDO libraries.  Exchange is currently Exchange Server 2003, soon to be replaced with Exchange 2010.
0
cmdown
Asked:
cmdown
  • 10
  • 7
  • 4
  • +2
1 Solution
 
cmdownAuthor Commented:
Hi kumaressan

Thanks for that.  The post from ShadowFox333 on the tek-tips article works and does not require CDO which is what was required.

The example defaults to a  read receipt request - is there a vbscript mapi paramater that disables this ?
0
 
cmdownAuthor Commented:
right - i've sorted the read receipt but i've hit another problem in that the script only works if outlook is already running.  This code is for a logon script (which I didn't say in my post !!)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
kumaresan2011Commented:
yes,, the com object invokes outlook. . when outlook is installed and outlook is running then only we can send mail...
0
 
kumaresan2011Commented:
can you explain me u r need in correctly... bcoz u no need this outlook method
so, what type u wants to send mail....
0
 
cmdownAuthor Commented:
One of the jobs of the logon script is to create a number of log files when a user logs into the computer.  If an error occurs during the logon process (adding printer, checking permission etc)  as well as writing the error to the log file we want to send an email to the ICT support desk to alert them to the error condition - it's always better for end-users to see the helpdesk as being proactive !  The old way was to use CDO but that is no longer an option.  Obviously as it is a logon script, Outlook wont be running so we need another way to achieve this.  If you want a copy of our login script let me know and I'll upload it.
0
 
kumaresan2011Commented:
please upload it ... i can get some idea
0
 
cmdownAuthor Commented:
Hi kumaresan - file attached.
Regards
ee-logonscript-v244.zip
0
 
Chris BottomleyCommented:
A basic script to send an email using outlook:

Chris
Set olkApp = CreateObject("outlook.application")
    With olkApp.CreateItem(0)
        .To = strTo
        .Subject = "SOmething about nothing"
        .body = "Head and shoulders above the rest"
            .Send
    End With

Open in new window

0
 
cmdownAuthor Commented:
Hello Chris

Thanks for your reply. I must have missed the 'comment added' notification from EE - sorry for the delay. I'll test this today and let you know.
0
 
cmdownAuthor Commented:
Hi Chris

Sorry - still no joy. This throws an error at the point of sending.  When run from an active windows session the code below works but doesn't work when trying to send an email from the login script which is the aim of the exercise.

      On Error Resume Next
      Set OlkApp = CreateObject("Outlook.Application")
      Set NewMail = OlkApp.CreateItem(olMailItem)
      With NewMail
            .To = "user@domain.com"
            .Subject = "Login Script Email Test"
            .Body = "Test email from Computer "
            .Importance = 2
            .Send
      End With

(code sample from http://www.tek-tips.com/viewthread.cfm?qid=276168&page=1157)
0
 
Chris BottomleyCommented:
Your code as presented wouldn't work as you are using the constant olMailItem

Replace that with 0 as per my sample
0
 
cmdownAuthor Commented:
Hi Chris

Still no joy - throws error code -2147467260
Chris
0
 
Chris BottomleyCommented:
From the earlier sequence CDO is no good either?

Chris
0
 
cmdownAuthor Commented:
Hi Chris, that is correct.  We have predominantly Office 2010 (with a very small number of 2007) and CDO is not a part of this.
0
 
Chris BottomleyCommented:
Step back to the solution that dependant on outlook and see if the following addition helps:


set sh = createobject("wscript.shell")
shell.run "outlook.exe"

your code

Chrs
0
 
cmdownAuthor Commented:
Hi Chris

The code works without your additional mod on XPPro computers but not on Win7.  Adding the objShell.Run("outlook.exe") forces Win7 to send the email but it brings up a warning message saying that an application is trying to send an email on my behalf (attached).  Can this be supressed?
ScreenShot030.png
0
 
Chris BottomleyCommented:
Yes it can be suppressed:

1. You can modify your code to use redemption: | http://www.dimastr.com/redemption/
2. You can use an outlook add-in i.e: | http://www.mapilab.com/outlook/security
3. Or finally you can use clickyes | http://www.contextmagic.com/

From my perspective ... if you do a lot of VBA programming then redemption is a good solution ... personally I rarely use it now.  I now use the maplab security add-in of option 2.  The first time you do something it asks if you want to continue, and if you click the always take this option it never bothers you again ... and it's free for both personal and commercial usage.
3. Personally I have never used clickyes but there are those who advocate so I include it for information"

Chris
0
 
cmdownAuthor Commented:
Hi Chris

Thanks for that.  I'm back in the office on Tuesday and will give that a go.
0
 
Glen KnightCommented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
Chris BottomleyCommented:
The use of she'll resolves the concern as. Stated by the OP.  the security warning whilst side issue should be addressed by use of one of the identified add ins and therefore the solution is as above

Chris
0
 
Chris BottomleyCommented:
As mentioned in Http:#a36028027

Chris
0
 
Vee_ModCommented:
All,
 
Following an 'Objection' by chris_bottomley (at http://www.experts-exchange.com/Q_27555604.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
Vee_Mod
Community Support Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 10
  • 7
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now