Jump to content

ASP send mail with JavaScript?


nnmlss

Recommended Posts

Is it possible to use JavaScript to send mails using CDOSYS ?I'm developing an ASP website with JavaScript instead of VBScript.If I remember well, I cannot use the both. Everywhere I look, i see only VBScript tutorials for sending mails.I did a form, send with POST to another page, validate emails and names and.. now I have to send mails. But.. everything i write as code is with JavaScript... Any idea what can I do?

Link to comment
Share on other sites

I would much rather use JavaScript for ASP pages as well but the sad truth is there are very few if any tutorials that use JavaScript examples.I even bought a ASP book that started of providing vbscript and javascript examples but stopped after the second chapter and only gave vbscript. I gave up and gave into vbscript.I am very happy to see that did not happen with ASP.Net. C# is used more often then VB...from what I have sen it is probably about 55-45 or 60-40%

Link to comment
Share on other sites

Here's an example:

function send_email_func (to, from, subject, body){  mailobj = Server.CreateObject("CDO.Message");  mailobj.From = from;  mailobj.To = to;  mailobj.Subject = subject;  mailobj.TextBody = body;  mailobj.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1;  mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com";  mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25;  mailobj.Configuration.Fields.Update();  mailobj.Send();  delete mailobj;}

And here's a thread where I talk to myself about this:http://w3schools.invisionzone.com/index.php?showtopic=6072Unfortunately, the Microsoft documentation for some of the configuration options is both extremely hard to find and completely inadequate for describing what is available. The documentation is basically unusable in any practical sense.Yeah, sadly, there isn't a lot of support for developing ASP in Javascript. Microsoft just pushes VB so much. It's still not clear to me what Microsoft has to gain by people programming in VB instead of Javascript.

Link to comment
Share on other sites

lol.. I don't think VBScript is better than JavaScript too.. If u ask me, I would not even use ASP, because of the Microsoft (mono)policy, but.. the client for the site I do has a STRONG CORPORATE REQUIREMENTS which I have to pass... And all of them are Microsoft orientated. I think this is what microsoft gains - the trust of the Big Companies, for the Big Contracts, about the big money. Nothing less.. VBScript is a Microsoft tehnology ant it must look like it is better then JScript. Check for JavaScript ASP tutorials? there's a few.. Check for VBScript? loool! :)whatever..thankx for the script, but.. when I test it locally there's an error..

Error Type:CDO.Message.1 (0x80040222)The pickup directory path is required and was not specified. /n2/sendmails.asp, line 16

have any idea what is it?pickup directory for what?line 16 is:

  mailobj.Send();

[edit:]yup, I did not specify smtp server.. :)

Link to comment
Share on other sites

Did you get it worked out? The pickup directory is a directory on the mail server that holds email, which the server monitors and sends out the messages as they get put in there. You can try changing the sendusing option to 2 or 3 and see if there is any difference. But for bulk mail, using option 2 is way too slow.

Link to comment
Share on other sites

Yestarday I have read a loooot of documentation about it, including online resourses, microsoft IIS smtp help and I found what for is the pickup directory. So.. I changed the path to but.. look what happens:

mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1; mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")="C:\Inetpub\mailroot\Pickup";Error Type:CDO.Message.1 (0x80070003)The system cannot find the path specified.

I tried to change the value of this attribute and check out what will be happen . The results are below..

mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;Error Type:(0x8004020F)The event class for this subscription is in an invalid partition

mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 3;Error Type:CDO.Message.1 (0x80040233)Could not find the Sender's mailbox.

All of this Errors point to the same line in the code:

  mailobj.Send();

I have opended the mmc console and check out smtp settings, but.. nothin unusal was there. And I trided to find anything and anything, but.. the script did not work. Post in a bulgarian forum and few of people there give me some piece of advice, but.. the situation is still unchanged.. I Failed. Cannot do anything else

Link to comment
Share on other sites

thankx :]it works! I saw somewhere cause I have to use doudble slashes \\ but.. didn't get it? Now it works. Thank you very much for the support. and thankx for the text editor ConTEXT, i get i from the links in your message, and this is the best one I have ever tried. Cheers!

Link to comment
Share on other sites

Cool, glad you like it. Hopefully we get a major update this summer (or winter, depending which hemisphere you live in..).Escaping slashes is necessary because a slash is used as an "escape character". This means that you can follow the slash with certain special characters to print non-typable characters, like these:\n - newline\r - carriage return\t - tabetc. So, when you want to print a slash itself, you have to escape it with another slash. You can also use them to print quotes in a quoted string:"this string has \"quotes\" in it."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...