• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Scheduled Task to run VB Script - send email

Hi,

I have the following code created as .VBS file and I set the scheduled task to run this weekly.
However, as I'm running this off my laptop where my outlook prompts me to connect or not.
Thus when this starts running - it'll gives me the outlook prompt and then it has the another prompt to ask "A program is trying to send an email on your behalf. Do you want to aloow this?"

Is there any way I make the code to skip both of the prompts?

"Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)

myItem.To = "test@testing.com"
myItem.Subject = "Message for you sir!"
myItem.Body = "Body here."

myItem.Send "

Thanks, any help would be appreciated.
0
cyberp
Asked:
cyberp
  • 2
2 Solutions
 
Dave BrettVice President - Business EvaluationCommented:
Hi cyberp,

a)

Whats the connection message? Is your Outlook instance visisble?

For b)

Using the Redemption.dll is your best bet, see http://www.outlookcode.com/d/sec.htm

Others prefer this program which monitors the security message and clicks it for you, http://www.contextmagic.com/express-clickyes/

Cheers

Dave
0
 
David LeeCommented:
Hi brettdj,

If Outlook isn't already running, then you have to log in to an Outlook profile to avoid the first of the two prompts.  brettdj has already covered the second prompt and how to get around it.  Here's your code modified to avoid the first prompt:

Set myOlApp = CreateObject("Outlook.Application")
Set myOlNS = myOlApp.GetNameSpace("MAPI")
'Change ProfileName on the next line to the name of your Outlook profile
myOlNS.Logon ProfileName
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.To = "test@testing.com"
myItem.Subject = "Message for you sir!"
myItem.Body = "Body here."
myItem.Send
myOlNS.Logoff
'You should always dispose of objects before ending the script.  This helps avoid memory leaks.
Set myItem = Nothing
Set myOlNS = Nothing
Set myOlApp = Nothing

Cheers!
0
 
David LeeCommented:
Oops, my previous post should have been addressed to cyberp not brettdj.  Sorry.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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