PDA

View Full Version : Javascripts to send email to many recipients



terkini
08-21-2006, 07:44 PM
Hi guys! Can anybody help me? I am not sure whether the script that I am going to describe below has ever been written or not, but i couldn't find such script anywhere. The main purpose of the script that I wanted below is to save my time typing the names of recipients of my email.
I have about 60 students in my class and i have all their email addresses. What I want to do is to have a web page (lets call this the "master page")with all their names listed in it, and next to each of their names are check box. Whenever I want to send email to some of them (say, to about 30 of them), I just check the box next to their names. After that, when i push a button (say, labelled "next"), my default email's "compose box" will appear with all the selected names listed as recipients of my email.
I would also like to have a "select all" check box on the master page so that whenever I want to send an email to all my students, i just check the "select all" box and all their names will be listed as recipients in my email's compose box.
I hope you guys can understand my description above.

mburt
08-21-2006, 08:42 PM
Id all of the checkboxes a1, a2, a3, etc.

Store them in an array, and call them in a loop:

<script type="text/javascript">
var boxes = new Array("a1","a2","a3","a4","a5","a6")
function checkall() {
for (i=0;i<=boxes.length-1;i++) {
var allboxes = document.getElementById(boxes[i])
allboxes.checked=true
}
}
</script>

mburt
08-21-2006, 08:44 PM
This would be an example of the full script:


<html>
<head>
<script type="text/javascript">
var boxes = new Array("a1","a2","a3","a4","a5","a6")
function checkall() {
for (i=0;i<=boxes.length-1;i++) {
var allboxes = document.getElementById(boxes[i])
if (allboxes.checked==false) {allboxes.checked=true}
else {allboxes.checked=false}
}
}
</script>
</head>
<body>
<input type="button" value="Check/Uncheck All" onclick="checkall()">
<br><input type="checkbox" id="a1">Student 1
<br><input type="checkbox" id="a2">Student 2
<br><input type="checkbox" id="a3">Student 3
<br><input type="checkbox" id="a4">Student 4
<br><input type="checkbox" id="a5">Student 5
<br><input type="checkbox" id="a6">Student 6
</body>
</html>

terkini
08-22-2006, 03:32 AM
This would be an example of the full script:


<html>
<head>
<script type="text/javascript">
var boxes = new Array("a1","a2","a3","a4","a5","a6")
function checkall() {
for (i=0;i<=boxes.length-1;i++) {
var allboxes = document.getElementById(boxes[i])
if (allboxes.checked==false) {allboxes.checked=true}
else {allboxes.checked=false}
}
}
</script>
</head>
<body>
<input type="button" value="Check/Uncheck All" onclick="checkall()">
<br><input type="checkbox" id="a1">Student 1
<br><input type="checkbox" id="a2">Student 2
<br><input type="checkbox" id="a3">Student 3
<br><input type="checkbox" id="a4">Student 4
<br><input type="checkbox" id="a5">Student 5
<br><input type="checkbox" id="a6">Student 6
</body>
</html>

Thanks, but your scripts only take care of the first part of the process i.e. to select the recipients. The second part of the process is to upload the selected people's email addresses into my email's compose box. I am not sure whether this can be done by javascripts.

terkini
08-23-2006, 05:51 AM
Thanks, but your scripts only take care of the first part of the process i.e. to select the recipients. The second part of the process is to upload the selected people's email addresses into my email's compose box. I am not sure whether this can be done by javascripts.

Can anybody help me to come up with the script to upload/transfer the email address of the selected people into my email's "compose" box? I roughly know that the function is "onSubmit" but I don't know how to write it.

DimX
08-23-2006, 06:14 AM
You can't transfer emails with javascript, you need some server side scripting to do that.

terkini
08-23-2006, 10:07 AM
You can't transfer emails with javascript, you need some server side scripting to do that.
Really?? I thought sometime ago i come across a javascript that can call-up the email's "compose" box with the subject and the recipient's name on it, and all you have to do is push the "send" button.

DimX
08-23-2006, 10:39 AM
Oh, you mean that, it's just a link:


<a href="mailto:mymail@mail.com?subject=Hallo%20there...&body=Message%20body%20comes%20here.">Email me</a>

But yes, if you want to capture user input first then you'll need to use javascript.

Here, I made you a small example: http://roboweb.awardspace.com/email.html

mwinter
08-23-2006, 01:50 PM
Really?? I thought sometime ago i come across a javascript that can call-up the email's "compose" box with the subject and the recipient's name on it, and all you have to do is push the "send" button.

You are referring to mailto links. These are unreliable and shouldn't be used to pre-compose an e-mail: they rely on the user having a mail client installed (not always the case for shared machines and irrelevant to visitors that would use a Web interface like Hotmail or Gmail), a browser that understands the mailto scheme, and an established relationship between the two.

The use of form mail - using the server to send mail - only depends upon the HTTP protocol (which is guaranteed).

Mike

DimX
08-23-2006, 02:24 PM
You are referring to mailto links. These are unreliable and shouldn't be used to pre-compose an e-mail: they rely on the user having a mail client installed (not always the case for shared machines and irrelevant to visitors that would use a Web interface like Hotmail or Gmail), a browser that understands the mailto scheme, and an established relationship between the two.
I don't believe (s)he wants to publish that page, (s)he just wants to simplify the way (s)he sends mails to students.

terkini
08-24-2006, 03:27 AM
I don't believe (s)he wants to publish that page, (s)he just wants to simplify the way (s)he sends mails to students.
you are right. I am looking for ways to simplify sending emails to my students. I cannot use the email's address book because the students grouping keep on changing based on quite a number of criterias (which change almost on daily basis). There is no problem with the default email clients in the students pc because each and every one of them have their own pc or laptop. It look like that there are quite a number of things javascript cannot do, and it look like that i have to do it the traditional way too i.e. type their name one by one. :o

jscheuer1
08-24-2006, 05:48 AM
This can be done if your email client will accept multiple recipients via a mailto: statement, many will. I'll have to knock it around a bit but, I am certain this can be done as a local javascript front-end for your own use with only your own email program, if it can accept the multiple recipients.

mwinter is absolutely correct in that this would not be suitable for live use as there are many things that might not work on any given person's set up. For that, as mwinter says, one would need a server side mail program.

jscheuer1
08-24-2006, 06:29 AM
Try this out:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Local Javascript Bulk eMailer - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

/*Local Javascript Bulk eMailer script
*As first seen in http://www.dynamicdrive.com/forums
*This notice must remain for legal use. */

function checkall(check) {
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (check=='t')
boxes[i].checked=boxes[i].checked==true? false : true;
else if (check)
boxes[i].checked=true;
else
boxes[i].checked=false;
}
function compose(){
var addys='', boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (boxes[i].checked)
addys+=boxes[i].value+', ';
addys=addys.replace(/, $/, '');
var mailwin=window.open('mailto:'+addys);
mailwin.close();
}
</script>
</head>
<body>
<input type="button" value="Check All" onclick="checkall(1);"> <input type="button" value="Uncheck All" onclick="checkall();"> <input type="button" value="Toggle All" onclick="checkall('t');">
<div id="boxes">
<input type="checkbox" value="Student1@school.edu">Student 1<br>
<input type="checkbox" value="Student2@school.edu">Student 2<br>
<input type="checkbox" value="Student3@school.edu">Student 3<br>
<input type="checkbox" value="Student4@school.edu">Student 4<br>
<input type="checkbox" value="Student5@school.edu">Student 5<br>
<input type="checkbox" value="Student6@school.edu">Student 6
</div>
<input type="button" value="Compose" onclick="compose();">
</body>
</html>

DimX
08-24-2006, 07:02 AM
It look like that there are quite a number of things javascript cannot do, and it look like that i have to do it the traditional way too i.e. type their name one by one. :o
Hey :p I gave you a link in my earlier post allready. http://roboweb.awardspace.com/email.html

jscheuer1
08-24-2006, 07:11 AM
Hey :p I gave you a link in my earlier post allready. http://roboweb.awardspace.com/email.html

Not bad DimX but, more complicated to maintain than my version:

http://www.dynamicdrive.com/forums/showpost.php?p=50352&postcount=13

DimX
08-24-2006, 07:20 AM
Yes, your code is simpler (without these ids on every input). ;)
But you could replace boxes[ i ].checked=boxes[ i ].checked==true? false : true; with boxes[ i ].checked = !boxes[ i ].checked; :p

jscheuer1
08-24-2006, 07:43 AM
Yes, your code is simpler (without these ids on every input). ;)
But you could replace boxes[ i ].checked=boxes[ i ].checked==true? false : true; with boxes[ i ].checked = !boxes[ i ].checked; :p

Thanks. Um, yes I suppose but, such simplifications really have little effect on the performance or usability (usually, and particularly in this case) of a script. I try to go first for simplicity in markup in a situation like this. Ease of use, and all that.

Funny though, how similar our code really is, when you think about it.

mburt
08-27-2006, 02:16 PM
Hmm.... I thought the question was just asking for a check/uncheck buttonf or a list of checkboxes :) Well, I guess I was wrong. :p

jscheuer1
08-27-2006, 04:41 PM
Hmm.... I thought the question was just asking for a check/uncheck buttonf or a list of checkboxes :) Well, I guess I was wrong. :p

That was part of it, yes.

terkini
08-29-2006, 08:19 PM
That was part of it, yes.
The script that you wrote was great! However, i encounter another problem which could be more complicated. Is it posible to have another box next to the recipient's name which, if checked, will put the recipient's name under "c.c" instead of under "To".
Sometime I have to send the email to 30 students under the "To" and another 30 students under the "c.c". Is it possible to create another box next to the existing box i.e. next to the students' name (Lets call this boxes "Box A" and "Box B"). If i check Box A, the students will be listed under the "To:" section, and if I check Box B, the students will be listed under the "c.c" section.
Can the script be further modified to accomodate above problem?

DimX
08-29-2006, 10:15 PM
Sure: http://roboweb.awardspace.com/email.html ;)

terkini
08-30-2006, 04:57 AM
Sure: http://roboweb.awardspace.com/email.html ;)
Great!! this is exactly what i have in mind. But i noticed that whenever i press the "next" button, it will call up Outlook. How to make it call up my default email client which is Thunderbird? (and at home, Netscape!)

jscheuer1
08-30-2006, 06:50 AM
Despite reverting to the previous inefficient methods for organizing the markup of the script, DimX's version should be fine for calling up the default email client of whatever browser that it is being viewed in. If a given browser has no default email client configured, and it is on a windows system, the usual result is that Outlook will be launched, whether it has been configured or not.

mburt
08-30-2006, 01:21 PM
I suggest using the PHP mail function. Sends mail directly.

jscheuer1
08-30-2006, 04:51 PM
I suggest using the PHP mail function. Sends mail directly.

Generally a very good idea (PHP or another server side language) for these types of things but, that had already been eliminated for this particular project. If you read back over the thread you will see that this is because it is intended for local use only.

jscheuer1
08-31-2006, 03:10 AM
Here is a much simpler version to configure. All you need to do is set the names, email addresses and your preference as to number of columns near the top of the script here:


//Set student name and email for each student:
var students=[];
students[0]=['Student 1', 'Student1@school.edu'];
students[1]=['Student 2', 'Student2@school.edu'];
students[2]=['Student 3', 'Student3@school.edu'];
students[3]=['Student 4', 'Student4@school.edu'];
students[4]=['Student 5', 'Student5@school.edu'];
students[5]=['Student 6', 'Student6@school.edu'];

//Set number of columns for display:
var columns=4

One other user setting of note is in the style section, for the width of the name field in the table:


#boxes td.sname {
text-align:left;
width:200px; /*Set for width of name field in table*/
}

Here is the entire script and markup:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Local Javascript Bulk eMailer - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#controls {
width:25em;
text-align:center;
}
* html #controls {
width:400px;
}
#boxes {
margin:1em 0;
}
#boxes td {
text-align:center;
}
#boxes td.sname {
text-align:left;
width:200px; /*Set for width of name field in table*/
}
</style>
<script type="text/javascript">

/*Local Javascript Bulk eMailer script
*As first seen in http://www.dynamicdrive.com/forums
*This notice must remain for legal use. */

//Set student name and email for each student:
var students=[];
students[0]=['Student 1', 'Student1@school.edu'];
students[1]=['Student 2', 'Student2@school.edu'];
students[2]=['Student 3', 'Student3@school.edu'];
students[3]=['Student 4', 'Student4@school.edu'];
students[4]=['Student 5', 'Student5@school.edu'];
students[5]=['Student 6', 'Student6@school.edu'];

//Set number of columns for display:
var columns=4

////////////// Stop Editing ///////////////////

function checkall(mcc, check) {
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (check=='t'){
if (mcc=='m'&&boxes[i].name=='mail')
boxes[i].checked=boxes[i].checked? false : true;
else if (mcc=='c'&&boxes[i].name=='cc')
boxes[i].checked=boxes[i].checked? false : true;
else if (mcc=='t')
boxes[i].checked=boxes[i].checked? false : true;
}
else if (check){
if (mcc=='m'&&boxes[i].name=='mail')
boxes[i].checked=true;
else if (mcc=='c'&&boxes[i].name=='cc')
boxes[i].checked=true;
}
else{
if (mcc=='m'&&boxes[i].name=='mail')
boxes[i].checked=false;
else if (mcc=='c'&&boxes[i].name=='cc')
boxes[i].checked=false;
}
}
function compose(){
var addys='', cc='?cc=', boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (boxes[i].checked&&boxes[i].name=='mail')
addys+=boxes[i].value+', ';
else if (boxes[i].checked&&boxes[i].name=='cc')
cc+=boxes[i].value+', ';
addys=addys.replace(/, $/, '');
cc=cc!='?cc='? cc.replace(/, $/, '') : '';
var mailwin=window.open('mailto:'+addys+cc);
mailwin.close();
}
</script>
</head>
<body>
<div id="controls">
<input type="button" value="Check mailto" onclick="checkall('m',1);"> <input type="button" value="Uncheck mailto" onclick="checkall('m');"> <input type="button" value="Toggle mailto" onclick="checkall('m','t');"><br>
<input type="button" value="Check CC" onclick="checkall('c',1);"> <input type="button" value="Uncheck CC" onclick="checkall('c');"> <input type="button" value="Toggle CC" onclick="checkall('c','t');"><input type="button" value="Toggle All" onclick="checkall('t','t');">
</div>
<table id="boxes">
<tr>
<td>Mail</td><td>&nbsp;CC&nbsp;</td><td></td>
<script type="text/javascript">
for (var i_tem = 1; i_tem < columns; i_tem++)
document.write('<td>Mail</td><td>&nbsp;CC&nbsp;</td><td></td>');
document.write('</tr><tr>');
for (i_tem = 0; i_tem < students.length; i_tem++){
document.write('<td><input name="mail" type="checkbox" value="'+students[i_tem][1]+'"></td><td><input name="cc" type="checkbox" value="'+students[i_tem][1]+'"></td><td class="sname">'+students[i_tem][0]+'</td>\n');
if(columns==0||columns==1||(i_tem!=0&&[i_tem+1]%columns==0))
document.write('</tr><tr>');
}
</script>
</table>
<input type="button" value="Compose" onclick="compose();">
</body>
</html>

jscheuer1
08-31-2006, 07:39 AM
Just for kicks, I decided to run my code through both the HTML and the css validator at the w3c. It passed the css - first try. But, there were some minor HTML problems and then I also realized that there were way too many ways that a student could end up receiving both an email and a CC of the same message. I put in some error checking for that as well as fixing the HTML validation problems (configuration is identical to the previous version):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Local Javascript Bulk eMailer - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#controls {
width:25em;
text-align:center;
}
* html #controls {
width:400px;
}
#boxes {
margin:1em 0;
}
#boxes td {
text-align:center;
}
#boxes td.sname {
text-align:left;
width:200px; /*Set for width of name field in table*/
}
</style>
<script type="text/javascript">

/*Local Javascript Bulk eMailer script
*As first seen in http://www.dynamicdrive.com/forums
*This notice must remain for legal use. */

//Set student name and email for each student:
var students=[];
students[0]=['Student 1', 'Student1@school.edu'];
students[1]=['Student 2', 'Student2@school.edu'];
students[2]=['Student 3', 'Student3@school.edu'];
students[3]=['Student 4', 'Student4@school.edu'];
students[4]=['Student 5', 'Student5@school.edu'];
students[5]=['Student 6', 'Student6@school.edu'];

//Set number of columns for display:
var columns=2

////////////// Stop Editing ///////////////////

function checkall(mcc, check) {
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (check=='t'){
if (mcc=='m'&&boxes[i].name=='mail'){
boxes[i].checked=boxes[i].checked? false : true;
boxes[i+1].checked=boxes[i].checked? false : boxes[i+1].checked;
}
else if (mcc=='c'&&boxes[i].name=='cc'){
boxes[i].checked=boxes[i].checked? false : true;
boxes[i-1].checked=boxes[i].checked? false : boxes[i-1].checked;
}
else if (mcc=='t'){
boxes[i].checked=boxes[i].checked? false : true;
if (i%2==0)
boxes[i+1].checked=boxes[i].checked? true : boxes[i+1].checked;
}
}
else if (check){
if (mcc=='m'&&boxes[i].name=='mail'){
boxes[i].checked=true;
checkall('c');
}
else if (mcc=='c'&&boxes[i].name=='cc'){
boxes[i].checked=true;
checkall('m');
}
}
else{
if (mcc=='m'&&boxes[i].name=='mail')
boxes[i].checked=false;
else if (mcc=='c'&&boxes[i].name=='cc')
boxes[i].checked=false;
}
}
function compose(){
var addys='', cc='?cc=', boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (boxes[i].checked&&boxes[i].name=='mail')
addys+=boxes[i].value+', ';
else if (boxes[i].checked&&boxes[i].name=='cc')
cc+=boxes[i].value+', ';
addys=addys.replace(/, $/, '');
cc=cc!='?cc='? cc.replace(/, $/, '') : '';
var mailwin=window.open('mailto:'+addys+cc);
mailwin.close();
}

onload=function(){
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i_tem = 0; i_tem < boxes.length; i_tem++)
if (boxes[i_tem].name=='mail'){
boxes[i_tem].id='mail'+i_tem;
boxes[i_tem+1].id='cc'+[i_tem+1];
boxes[i_tem].onclick=new Function("if(this.checked)document.getElementById('cc"+[i_tem+1]+"').checked=false");
}
else
boxes[i_tem].onclick=new Function("if(this.checked)document.getElementById('mail"+[i_tem-1]+"').checked=false");
}
</script>
</head>
<body>
<div id="controls">
<input type="button" value="Check mailto" onclick="checkall('m',1);"> <input type="button" value="Uncheck mailto" onclick="checkall('m');"> <input type="button" value="Toggle mailto" onclick="checkall('m','t');"><br>
<input type="button" value="Check CC" onclick="checkall('c',1);"> <input type="button" value="Uncheck CC" onclick="checkall('c');"> <input type="button" value="Toggle CC" onclick="checkall('c','t');"><input type="button" value="Toggle All" onclick="checkall('t','t');">
</div>
<table id="boxes">
<tr>
<td>Mail</td><td>&nbsp;CC&nbsp;</td><td>
<script type="text/javascript">
document.write('<\/td>')
for (var i_tem = 1; i_tem < columns; i_tem++)
document.write('<td>Mail<\/td><td>&nbsp;CC&nbsp;<\/td><td><\/td>');
document.write('<\/tr><tr>');
for (i_tem = 0; i_tem < students.length; i_tem++){
document.write('<td><input name="mail" type="checkbox" value="'+students[i_tem][1]+'"><\/td><td><input name="cc" type="checkbox" value="'+students[i_tem][1]+'"><\/td><td class="sname">'+students[i_tem][0]+'<\/td>\n');
if(columns==0||columns==1||(i_tem!=0&&[i_tem+1]%columns==0))
document.write('<\/tr><tr>');
}
</script>
</table>
<div><input type="button" value="Compose" onclick="compose();"></div>
</body>
</html>

mburt
08-31-2006, 11:14 AM
Hmm... I find the mailto: function very annoying though... But if it's only for someone's own personaly use this is perfect :) Nice work jscheuer :p

mburt
08-31-2006, 11:16 AM
I just tested it, and this is amazingly efficient. I thought it would open up a million "Outlook Express" boxes :) Awesome...

terkini
09-04-2006, 05:43 AM
Just for kicks, I decided to run my code through both the HTML and the css validator at the w3c. It passed the css - first try. But, there were some minor HTML problems and then I also realized that there were way too many ways that a student could end up receiving both an email and a CC of the same message. I put in some error checking for that as well as fixing the HTML validation problems (configuration is identical to the previous version):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Local Javascript Bulk eMailer - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#controls {
width:25em;
text-align:center;
}
* html #controls {
width:400px;
}
#boxes {
margin:1em 0;
}
#boxes td {
text-align:center;
}
#boxes td.sname {
text-align:left;
width:200px; /*Set for width of name field in table*/
}
</style>
<script type="text/javascript">

/*Local Javascript Bulk eMailer script
*As first seen in http://www.dynamicdrive.com/forums
*This notice must remain for legal use. */

//Set student name and email for each student:
var students=[];
students[0]=['Student 1', 'Student1@school.edu'];
students[1]=['Student 2', 'Student2@school.edu'];
students[2]=['Student 3', 'Student3@school.edu'];
students[3]=['Student 4', 'Student4@school.edu'];
students[4]=['Student 5', 'Student5@school.edu'];
students[5]=['Student 6', 'Student6@school.edu'];

//Set number of columns for display:
var columns=2

////////////// Stop Editing ///////////////////

function checkall(mcc, check) {
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (check=='t'){
if (mcc=='m'&&boxes[i].name=='mail'){
boxes[i].checked=boxes[i].checked? false : true;
boxes[i+1].checked=boxes[i].checked? false : boxes[i+1].checked;
}
else if (mcc=='c'&&boxes[i].name=='cc'){
boxes[i].checked=boxes[i].checked? false : true;
boxes[i-1].checked=boxes[i].checked? false : boxes[i-1].checked;
}
else if (mcc=='t'){
boxes[i].checked=boxes[i].checked? false : true;
if (i%2==0)
boxes[i+1].checked=boxes[i].checked? true : boxes[i+1].checked;
}
}
else if (check){
if (mcc=='m'&&boxes[i].name=='mail'){
boxes[i].checked=true;
checkall('c');
}
else if (mcc=='c'&&boxes[i].name=='cc'){
boxes[i].checked=true;
checkall('m');
}
}
else{
if (mcc=='m'&&boxes[i].name=='mail')
boxes[i].checked=false;
else if (mcc=='c'&&boxes[i].name=='cc')
boxes[i].checked=false;
}
}
function compose(){
var addys='', cc='?cc=', boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (boxes[i].checked&&boxes[i].name=='mail')
addys+=boxes[i].value+', ';
else if (boxes[i].checked&&boxes[i].name=='cc')
cc+=boxes[i].value+', ';
addys=addys.replace(/, $/, '');
cc=cc!='?cc='? cc.replace(/, $/, '') : '';
var mailwin=window.open('mailto:'+addys+cc);
mailwin.close();
}

onload=function(){
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i_tem = 0; i_tem < boxes.length; i_tem++)
if (boxes[i_tem].name=='mail'){
boxes[i_tem].id='mail'+i_tem;
boxes[i_tem+1].id='cc'+[i_tem+1];
boxes[i_tem].onclick=new Function("if(this.checked)document.getElementById('cc"+[i_tem+1]+"').checked=false");
}
else
boxes[i_tem].onclick=new Function("if(this.checked)document.getElementById('mail"+[i_tem-1]+"').checked=false");
}
</script>
</head>
<body>
<div id="controls">
<input type="button" value="Check mailto" onclick="checkall('m',1);"> <input type="button" value="Uncheck mailto" onclick="checkall('m');"> <input type="button" value="Toggle mailto" onclick="checkall('m','t');"><br>
<input type="button" value="Check CC" onclick="checkall('c',1);"> <input type="button" value="Uncheck CC" onclick="checkall('c');"> <input type="button" value="Toggle CC" onclick="checkall('c','t');"><input type="button" value="Toggle All" onclick="checkall('t','t');">
</div>
<table id="boxes">
<tr>
<td>Mail</td><td>&nbsp;CC&nbsp;</td><td>
<script type="text/javascript">
document.write('<\/td>')
for (var i_tem = 1; i_tem < columns; i_tem++)
document.write('<td>Mail<\/td><td>&nbsp;CC&nbsp;<\/td><td><\/td>');
document.write('<\/tr><tr>');
for (i_tem = 0; i_tem < students.length; i_tem++){
document.write('<td><input name="mail" type="checkbox" value="'+students[i_tem][1]+'"><\/td><td><input name="cc" type="checkbox" value="'+students[i_tem][1]+'"><\/td><td class="sname">'+students[i_tem][0]+'<\/td>\n');
if(columns==0||columns==1||(i_tem!=0&&[i_tem+1]%columns==0))
document.write('<\/tr><tr>');
}
</script>
</table>
<div><input type="button" value="Compose" onclick="compose();"></div>
</body>
</html>
I have run this script again and find that this script is working perfectly in Netscape but not in IE and Firefox. Whenever I use this script with IE or Firefox, the OUTLOOK.EXE box will appear with the following message:
"The ordinal 36 could not be located in the dynamic link library MAPI32.dll"
Can somebody please tell me whether the problem is with my PC or the script?
Thank you.

jscheuer1
09-04-2006, 07:00 AM
I've come up with an even more advanced version of the script which optionally sorts the names into vertical columns alphabetically. But, let's first see what's what with this error you are getting.

Two ground rules:

1 ) The page must be used only locally on the computer with the browser that you are talking about.

2 ) Said browser must have an email client configured for it.

If you have got that covered, a simple test of if it is the script or the computer would be to load this page in the browser:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Email Test Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<a href="mailto:someone@some.com">test one</a><br>
<a href="mailto:someone@some.com" onclick="window.open(this.href,this.target);return false;" target="_blank">test two</a>
</body>
</html>

If test one gives an error, then it is your computer/browser.

If test one works and test two fails, it is the script.

If both tests work but the script that you want to use still doesn't work, it is also the script but, for a different reason.

oriecat
09-06-2006, 08:04 PM
Hi, I am looking for something like this also, but for use online for our employees. All employees have Outlook Express, so that concern earlier wouldn't be a problem... but I have a couple other things I would like to do... I would like to list each employee, along with their location and department, and then have hot keys where all employees in a certain location or department would be checked, or if both location and department were checked, it would only send if both were checked, filtering the selection down... is this possible?

jscheuer1
09-07-2006, 05:44 AM
Hi, I am looking for something like this also, but for use online for our employees. All employees have Outlook Express, so that concern earlier wouldn't be a problem... but I have a couple other things I would like to do... I would like to list each employee, along with their location and department, and then have hot keys where all employees in a certain location or department would be checked, or if both location and department were checked, it would only send if both were checked, filtering the selection down... is this possible?

Yes, if the current version works. However, I'm not willing to take your word for the fact that 'everyone will be using Outlook Express'. Any online version should be done server side. There is no telling what this or that particular employee or employees might manage to access it with, especially in the future.

oriecat
09-07-2006, 03:17 PM
Hi, thanks for your reply. :) What does that mean "done server side"? Like on the email server? We are looking into that, but seems like it would require more work (or so I was told...). Or do you have a different recommended way I could achieve what I am trying to do? What exactly is the concern with the employees? Could they do something, or it just wouldn't work w/o the proper email client?

smandel
02-07-2007, 07:19 PM
I found your javascript code very useful. However, I already have a generated list prompt with my email addresses.

How would I be able to modify the javascript in order to capture multiple selections in my generated list prompt with email addresses?

Regards,
Shawn

Consigliere
10-27-2007, 11:34 AM
Try this out:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Local Javascript Bulk eMailer - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

/*Local Javascript Bulk eMailer script
*As first seen in http://www.dynamicdrive.com/forums
*This notice must remain for legal use. */

function checkall(check) {
var boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (check=='t')
boxes[i].checked=boxes[i].checked==true? false : true;
else if (check)
boxes[i].checked=true;
else
boxes[i].checked=false;
}
function compose(){
var addys='', boxes = document.getElementById('boxes').getElementsByTagName('input')
for (var i=0; i<boxes.length; i++)
if (boxes[i].checked)
addys+=boxes[i].value+', ';
addys=addys.replace(/, $/, '');
var mailwin=window.open('mailto:'+addys);
mailwin.close();
}
</script>
</head>
<body>
<input type="button" value="Check All" onclick="checkall(1);"> <input type="button" value="Uncheck All" onclick="checkall();"> <input type="button" value="Toggle All" onclick="checkall('t');">
<div id="boxes">
<input type="checkbox" value="Student1@school.edu">Student 1<br>
<input type="checkbox" value="Student2@school.edu">Student 2<br>
<input type="checkbox" value="Student3@school.edu">Student 3<br>
<input type="checkbox" value="Student4@school.edu">Student 4<br>
<input type="checkbox" value="Student5@school.edu">Student 5<br>
<input type="checkbox" value="Student6@school.edu">Student 6
</div>
<input type="button" value="Compose" onclick="compose();">
</body>
</html>

To elaborate a little on jscheuer1's script, it has an error generated in the taskbar when you activate it. You can fix that problem by removing one line of code in the HEAD section. Just remove the below line of code and there will not be anymore error message generated.

mailwin.close();

By removing the above, it has no effect on the actions of the script other than there is no error message generated.

I have tested this code in IE 7.0, Firefox 2.0.0.8, Opera 9.24, Opera 9.50 Alpha, Netscape 9.0.0.1, Netscape 8.1.3, AOL Explorer 1.5 and Safari 3.0.2. This script worked with variations observed in all platforms with the exception of IE 7.0.

All platforms other than IE 7.0 could not sustain sending more than twenty (20) emails at a time.

With AOL Explorer 1.5 the browser would just close with no explanation.

With Firefox 2.0.0.8, Opera 9.24, Opera 9.50 Alpha, Netscape 9.0.0.1, Netscape 8.1.3 and Safari 3.0.2 you would receive a popup error message.

In IE 7.0 the maximum emails to be sent at one time is eighty (80). Any more than that the platform can not handle and would get an error and close.

oriecat
10-01-2008, 09:46 PM
Hi, I have been using this script for our employees, but now I need to convert it to a form mail instead of a compose box. Does anyone have any tips for me on how best to do that?

Thank you.

mking0310
02-26-2014, 10:16 PM
To elaborate a little on jscheuer1's script, it has an error generated in the taskbar when you activate it. You can fix that problem by removing one line of code in the HEAD section. Just remove the below line of code and there will not be anymore error message generated.

mailwin.close();

By removing the above, it has no effect on the actions of the script other than there is no error message generated.

I have tested this code in IE 7.0, Firefox 2.0.0.8, Opera 9.24, Opera 9.50 Alpha, Netscape 9.0.0.1, Netscape 8.1.3, AOL Explorer 1.5 and Safari 3.0.2. This script worked with variations observed in all platforms with the exception of IE 7.0.

All platforms other than IE 7.0 could not sustain sending more than twenty (20) emails at a time.

With AOL Explorer 1.5 the browser would just close with no explanation.

With Firefox 2.0.0.8, Opera 9.24, Opera 9.50 Alpha, Netscape 9.0.0.1, Netscape 8.1.3 and Safari 3.0.2 you would receive a popup error message.

In IE 7.0 the maximum emails to be sent at one time is eighty (80). Any more than that the platform can not handle and would get an error and close.


How do I add a subject and Body? I have been working on this for hours - I want to use the check box for the body and static address ...
var mailwin=window.open('mailto:'+""its_discussion_forum_reports@group.apple.com"'subject:'+"addys");