# VBForums CodeBank > CodeBank - JavaScript >  Avoid javascript email problems.

## SpagettiProg

Recently I had a problem where users when trying to click on a 
mailto button would get an error "The command line argument is not
valid". Which required a fix ...
http://support.microsoft.com/default...Product=ol2002 
So then I decided to use the outlook model, then a new error message came...
ActiveX component can't create object: 'Outlook.Application'
Thanks in part to Javascripts try catch, the code below defeats this
evil.

PS. If someone has problems with either, then it's time for a new machine :-)




```
function MakeEmailDecision(subject, tofield, body)
/* function that will decide if object model should be used
or if mailto should be used */
{
try
{
var myOlApp = new ActiveXObject("Outlook.Application");
var myOlExp = myOlApp.ActiveExplorer;
var myItem = myOlApp.CreateItem(Object.olMailItem);

			myItem.Subject = subject;
			myItem.Body = body;
			myItem.To = tofield;

			myOlExp.Activate();
			myItem.Display(); 

}
catch(err)
{	
	var mailto = 'mailto:' + tofield + '?subject=' + subject + '&body=' + body
window.location.href(mailto);	
}
}
```


I want to thank.......
http://www.vbforums.com/showthread.p...24#post2501224

----------

