Navigation

1/26/2015

Using javascript to create Outlook email message

Want to use HTML to open Outlook with new message, use script below (only in IE):

<script type="text/javascript">
function OpenOutlookDoc(email_address,body_stuff)
{
try
{

var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add('IPM.Note.FormA');
mailItem.Subject="a subject test";
mailItem.To = email_address;
mailItem.HTMLBody = body_stuff;
mailItem.display (0);
}
catch(e)
{
alert(e);
// act on any error that you get
}
}
</script>


<a href="javascript:OpenOutlookDoc('zzz@test.com','Body of message')">Click</a>


On first attempt, got error "Automation server can't create object."   Just need to do following to IE security settings: 

a) Go to Tools-->Internet Options
b) Select security tab
c) Click on Trusted Sites (or Local Intranet depending on whether your site is trusted or not)
d) Click on Custom Level
e) Ensure that "Initialize and script active x controls is not marked safe for scripting" is enabled - this comes under Activex controls and plug-ins section towards 1/4th of the scroll bar.
Click OK, OK.
Once this is completed, clear the browser cookies and cache. Close all your browser sessions. Reopen the IE to launch your site.
Try to disable the setting in step (e) to see if the problem comes back - that should give more insight to the problem.

1/15/2015

Visual basic to access CMD or Shell commands

Wanted to run CMD   NET USER /DOMAIN  
from vb script, and return password expiration date:



Dim objShell, objWshScriptExec, objStdOut, strLine, bolFoundFlag
bolFoundFlag = FALSE

Set objShell = CreateObject("WScript.Shell")
'Set objWshScriptExec = objShell.Exec("ipconfig /all")
Set objWshScriptExec = objShell.Exec("NET USER /DOMAIN " & strName)

Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine
   ' english windows
   If InStr(strLine,"Password expires") Then
       response.Write(strName & ":&nbsp;&nbsp; " & strLine & "<p>")
       bolFoundFlag = TRUE
   ' french windows      
   ElseIf InStr(strLine,"found") Then
      response.Write( strLine & "<p>")  
   End If
  
'   response.Write(strLine & " <br>")
Wend