views:

363

answers:

1

I have the following code where i could send mail through my configured outlook. I can run this vbs using a rule in my outlook which in turn send a mail to the email specified in the script

But i am getting a confirmation box asking a virus or not while running this script to send a mail.

How to get rid of this confirmation box to make always allow to send mails.

   Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment

Dim ol, ns, newMail

ToAddress = "[email protected]"   ' change this...
MessageSubject = "My Subject"
MessageBody = "DATA"

Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf

' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
   MsgBox "unknown recipient"
Else
   newMail.Recipients.Add(myRecipient)
   newMail.Send
End If

Set ol = Nothing
+1  A: 

I believe your being hit by the now built-in security feature(s) that Microsoft put in place a couple years back with a security patch. The only way I know around it to is to digitally sign the code and then import the certicate that was used to sign that code into the certificate store, or better yet use the Redemption DLL. From the Redemption DLL site:

Outlook Redemption works around limitations imposed by the Outlook Security Patch and Service Pack 2 of MS Office 98/2000 and Office 2002/2003/2007 (which include Security Patch) plus provides a number of objects and functions to work with properties and functionality not exposed through the Outlook object model.

The DLL can be downloaded from here: http://www.dimastr.com/redemption/download.htm, and if you look around you can find several examples of how to use it. Here is one to get you started: http://www.utteraccess.com/forums/printthread.php?Cat=&Board=80&main=409393&type=thread

Also please note the peviously posted and answered questions:

http://stackoverflow.com/questions/235231/how-to-avoid-outlook-security-alert-when-reading-outlook-message-from-c-program

http://stackoverflow.com/questions/639737/outlook-nagging-dialog-about-macro

mrTomahawk