Ayuda con la propiedad SendMail

Andry Rodr?ez P?z
02 de Septiembre del 2004
Hola amigos necesito ayuda con este código, tengo necesidad de enviar un mensaje a varias personas que estan en mi BD, utilizando la propiedad SendMail
, pero cada ves que realizo el envio ella me da error y necesito saber que es lo que sucede y aqui les va el código:

<%
function sendMail(Host,From,FromName,Subject,Body,To,msgType,embedFiles,bcc)
{
var Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = Host;
Mail.From = From;
Mail.FromName = FromName;
Mail.Subject = Subject;
if (msgType == "HTML" | msgType == "html")
{
Mail.isHTML = true;

if (parseInt(embedFiles) != 0)
{
for (i=0; i < embedFiles.length;i++)
{
tcad = String(embedFiles[i]);
splt = tcad.split("|");
Mail.AddEmbeddedImage (splt[0],splt[1]);
}
}
Mail.ContentTransferEncoding = 'quoted-printable';
}

Mail.Body = Body;
// Mail.AddAddress(To);

bccsplit = bcc.split(';');

if ( bcc.length > 0 )
{
for (x=0;x<(bccsplit.length-1);x++)
{
Mail.AddBcc(String(bccsplit[x]));
Response.Write(String(bccsplit[x])+'-'+'<br>');
}

try
{
Mail.Send();
return true;
} catch (x)
{
return false;
}
// Response.Write(bcc+'<br>');
}

}

%>

<!-- #include file="_includes/check_privileges.asp"-->
<%
if (!check_privileges(String(Session("privileges")),"admin|overlord|operator"))
{
Response.Redirect("access_denied.asp");
}
%>


<html>
<head>
</head>

<body>
<!-- #include file="_includes/check_frame.asp" -->

<%
var errors = '';
var id = String(Request.Form("id"));
var param = String(Request.Form("param"));

if (check_empty(id) | check_empty(param))
{
errors = 'Debe seleccionar algun elemento a enviar.'
}


if (errors != '')
{

%>
<form action="tool_send_public.asp" method="post" name="form1">
<input type="hidden" name="error" value="<%= errors %>">
</form>
<script language="JavaScript">
document.form1.submit();
</script>
<% } else {

if (param == 'one')
{
var to = String(Request.Form("to_email"));
var format = String(Request.Form("Format"));

if (check_empty(to) | check_empty(format) )
{
errors = 'Debe especificar una dirección de correo y un formato para el tipo de correo.';
} else {
if (!check_mail(to))
{
errors = 'La dirección de correo especificada no corresponde a una dirección de correo valida.';
}
}

}

if (errors == '')
{
var date = new Date();
var date_ = date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getYear();

var path = Server.MapPath(".");
path += '\_images\';

var addembed = new Array();
addembed[0] = path + 'tiny_logo.gif|My';
addembed[1] = path + 'publica.jpg|Left';
addembed[2] = path + 'left_banner.gif|Back';
addembed[3] = path + 'lup.gif|More';
addembed[4] = path + 'line.gif|Line';


var To_t = new Array();
var To_h = new Array();
var until_t = 0;
var until_h = 0;

if (param == 'one')
{
if (format == 'text')
{
To_t[0] = to;
} else {
To_h[0] = to;
}
}

if (param == 'subsc')
{
query = "SELECT email FROM subsc_user where validated=1 and deleted=0 and artiformat = 'html' ";
rs_users = rs_exe(query);

j = 0;
while (!rs_users.EOF)
{
To_h[j] = String(rs_users(0));
j++;
rs_users.MoveNext();
}
until_h = To_h.length-1;

query = "SELECT email FROM subsc_user where validated=1 and deleted=0 and artiformat='text'";
rs_users = rs_exe(query);

j = 0;
while (!rs_users.EOF)
{
To_t[j] = String(rs_users(0));
j++;
rs_users.MoveNext();
}
until_t = To_t.length-1;
}


if (param == 'all')
{
query = "SELECT email FROM subsc_user where deleted=0 and artiformat='html'";
rs_users = rs_exe(query);

j = 0;
while (!rs_users.EOF)
{
To_h[j] = String(rs_users(0));
j++;
rs_users.MoveNext();
}
until_h = To_h.length-1;

query = "SELECT email FROM subsc_user where deleted=0 and artiformat='text'";
rs_users = rs_exe(query);

j = 0;
while (!rs_users.EOF)
{
To_t[j] = String(rs_users(0));
j++;
rs_users.MoveNext();
}
until_t = To_t.length-1;
}

query = 'SELECT dbo.magazines_articles.Title, dbo.magazines.Comment, dbo.magazines.Vol, dbo.magazines.[No], dbo.magazines.[Date], dbo.magazines.pic, dbo.magazines.asesors, dbo.magazines_articles.Authors, dbo.magazines_articles.id, dbo.magazines_articles_type.name, dbo.magazines.id FROM dbo.magazines INNER JOIN dbo.magazines_articles ON dbo.magazines.id = dbo.magazines_articles.id_Revist INNER JOIN dbo.magazines_articles_type ON dbo.magazines_articles.ArtiType = dbo.magazines_articles_type.id WHERE dbo.magazines.id='+id+' ORDER BY dbo.magazines_articles_type.priority';

rs_News = rs_exe(query);

try
{
String(rs_News);
errors = 'Ha ocurrido un error, el servidor está de mantenimiento. Intentelo más tarde.';
} catch(x) {
if (rs_Empty(rs_News))
{
errors = 'No se seleccionó un elemento valido. Seleccione une publicación.';
}
}


if ( errors == '')
{
var rs_vol = '';
var rs_no = '';
var rs_date = '';
var rs_comment = '';
var rs_pic = '';
var rs_asesors = '';
var rs_articles = '<tr>';
var rs_articles_txt = '';

while (!rs_News.EOF)
{
rs_vol = String(rs_News(2));
rs_no = String(rs_News(3));
rs_date = extract_Date(String(rs_News(4)));
rs_comment = String(rs_News(1));
rs_pic = String(rs_News(5));
rs_asesors = String(rs_News(6));

var authors = String(rs_News(7));
spl_auth = authors.split("|");
var add_qry = '';
authors = '';
for ( i=0; i<spl_auth.length; i++)
{
qry = 'SELECT id, author, especiality FROM magazines_authors where id=' + spl_auth[i].substr(1,(spl_auth[i].length-2));
rs_GetAuthors = rs_exe(qry);

try
{
String(rs_GetAuthors);
authors += " - ";
} catch(x) {
authors += ' ' + unescape(rs_GetAuthors(2)) + ' ' + unescape(rs_GetAuthors(1)) + '&nbsp;&nbsp;&nbsp;';
}
}


rs_articles += '<td bgcolor="#EDF4F8"><a href="http://medisur.cfg.sld.cu/p_Article.asp?id='+rs_News(10)+'&art='+rs_News(8)+'&prm=rem" calss="zoom" target="_blank"><font face="Arial" style="font-size:12px"><font color="#006500">'+rs_News(0)+'</font></a><br><font color="#2E5CBE"><b>Tipo de artículo:</b> '+rs_News(9)+'<br><b>Autores:</b> '+authors+'</font></font></td></tr>';

rs_articles_txt += '----------------------------------------------------------------------------------------------------------'+ String.fromCharCode(13,10) + rs_News(0) + String.fromCharCode(13,10) +'----------------------------------------------------------------------------------------------------------' + String.fromCharCode(13,10) + 'Vínculo: http://medisur.cfg.sld.cu/p_Article.asp?id=' + rs_News(10) + '&art=' + rs_News(8) + '&prm=rem' + String.fromCharCode(13,10) +'Tipo de artículo: ' + rs_News(9) + String.fromCharCode(13,10) +'Autores: ' + clear_quotes(authors) + String.fromCharCode(13,10,13,10,13,10);

rs_News.MoveNext();
}
rs_articles += '</tr>';
///-------------------


body_part = '';
body_html = '';
body_text = '';

body_html = '<html><head><title>Medisur</title><style> A.zoom:visited {text-decoration:none; color:#000093;} A.zoom:link {text-decoration:none; color:#000093;} A.zoom:Hover {text-decoration:underline; color:#000093;} p { text-align : justify; }</style><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body background="cid:Back" leftmargin="8" topmargin="0" marginwidth="0" marginheight="0"><br><table width="175" border="0" cellpadding="2" cellspacing="0" bordercolor="#999999"><tr><td height="20" align="center" valign="bottom" bgcolor="#D2E4E6"><a href="http://medisur.cfg.sld.cu" target="_blank"><img src="http://medisur.cfg.sld.cu/medisur_admin/_images/tiny_logo.gif" width="120" height="22" border="0"></a></td> </tr></table><table width="600" border="1" cellpadding="0" cellspacing="0" bordercolor="#D2E4E6"> <tr> <td align="center" valign="top" bgcolor="#E6FFE6"><br><font color="#81B5BA" face="Arial" style="font-size:13px"><b>Revista Electr&oacute;nica de las Ciencias M&eacute;dicas en Cienfuegos</b></font><br><br><table width="520" border="0" cellpadding="1" cellspacing="0" bgcolor="#71B3FB"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="4"><tr><td align="center" valign="top" bgcolor="#E1ECF2"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#71B3FB"><b><font face="Tahoma" style="font-size:12px">&nbsp; Nueva publicaci&oacute;n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000093" face="Arial" style="font-size:12px">Vol: <font color="#714E6B" face="Arial" style="font-size:11px">' + rs_vol + '</font> &nbsp;&nbsp;No: <font color="#714E6B" face="Arial" style="font-size:11px">' + rs_no + '</font> &nbsp;&nbsp;Fecha: <font color="#714E6B" face="Arial" style="font-size:11px">' + rs_date + '</font> </font></b></td></tr></table><table width="100%" border="0" cellspacing="2" cellpadding="6"><tr><td width="50%" valign="top" bgcolor="#EDF4F8"><div align="justify"><img src="http://medisur.cfg.sld.cu/_publications/Vol1_No1/cover.gif" align="left" width="104" height="136"><font color="#000093" face="Arial" style="font-size:12px">' + clear_quotes(rs_comment.replace("'","''")) + '</font> </div><td width="30%" align="left" valign="top" bgcolor="#EDF4F8"><b><font color="#809BA8" face="Arial" style="font-size:13px"><font color="#5E7A88">Asesores del número:</font></b><br> <font style="font-size:12px"> ' + rs_asesors + '</font></td></tr></table> <br><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#71B3FB"><b><font face="Tahoma" style="font-size:12px">&nbsp; Artículos</font></b></td> </tr></table> <table width="100%" border="0" cellspacing="2" cellpadding="2"> ' + rs_articles + ' </table></td></tr></table></td></tr></table> <br><font color="#0099CC" face="Tahoma" style="font-size:11px"> <b>[ <a href="http://medisur.cfg.sld.cu/" target="_blank" class="zoom"><font color="#0099CC">Inicio</font></a> ][&nbsp;<a href="http://medisur.cfg.sld.cu/p_index.asp" target="_blank" class="zoom"><font color="#0099CC">Publicaciones</font></a> ][&nbsp;<a href="http://medisur.cfg.sld.cu/miemb.asp" target="_blank" class="zoom"><font color="#0099CC">Miembros</font></a> ][&nbsp;<a href="http://medisur.cfg.sld.cu/contac.asp" target="_blank" class="zoom"><font color="#0099CC">Contactos</font></a> ][&nbsp;<a href="http://medisur.cfg.sld.cu/sites_int.asp" target="_blank" class="zoom"><font color="#0099CC">Sitios de Interes</font></a> ]<br> [&nbsp;<a href="http://medisur.cfg.sld.cu/subs_index.asp" target="_blank" class="zoom"><font color="#0099CC">Suscripci&oacute;n</font></a> ][&nbsp;Hacerme Revisor ] [&nbsp;<a href="http://medisur.cfg.sld.cu/send_arti.asp" target="_blank" class="zoom"><font color="#0099CC">Envio de articulos</font></a> ] [&nbsp;<a href="http://medisur.cfg.sld.cu/normas.asp" target="_blank" class="zoom"><font color="#0099CC">Normas de Publicaci&oacute;n</font></a> ]</b></font><br><br><font face="Tahoma" style="font-size:10px" color="#009966"><b>Administrador:</b> <a href="mailto:[email protected]" class="zoom">Dr.C. Mikhail Benet Rodríguez</a><br><b>Dise&ntilde;ador y Webmaster:</b> <a href="mailto:[email protected]" class="zoom">Ing. Andry Rodríguez Pérez </a></font><br> <br><br><br><br> <font color="#5A0000" face="Tahoma" style="font-size:11px"> <b>Aclaración!!! :</b><br> Este mensaje no puede ser considerado como SPAM ya que el usuario solo lo recibe si se suscribió a nuestro servicio; además el usuario puede cancelar su suscripción accediendo al link <a href="http://medisur.cfg.sld.cu/subs_baja.asp" class="zoom">Cancelar suscripción</a><br></font> </td> <td align="center" valign="top" bgcolor="#D2E4E6"><img src="http://medisur.cfg.sld.cu/medisur/_images/publica.jpg" width="52" height="600"></td> </tr></table></body></html>';
//sendMail("169.158.166.216","[email protected]","Revista Medisur","Nueva publicación --- " + date_ ,body,spl[0],'HTML',addembed);
body_text = '--------------------------------------------------------------------------' + String.fromCharCode(13,10) + '| Medisur - Revista Electrónica de las Ciencias Médicas en Cienfuegos |' + String.fromCharCode(13,10) + '--------------------------------------------------------------------------' + String.fromCharCode(13,10) + ' | NUEVA PUBLICACIÓN | ' + String.fromCharCode(13,10) + ' ---------------------------------------' + String.fromCharCode(13,10,13,10,13,10) + 'Nueva publicación Vol:' + rs_vol + ' No: ' + rs_no + ' Fecha: ' + rs_date + String.fromCharCode(13,10) + '--------------------------------------------------------------------------' + String.fromCharCode(13,10,13,10) + '--------------------------------------------' + String.fromCharCode(13,10) + '| Comentario del número |' + String.fromCharCode(13,10) + '--------------------------------------------' + String.fromCharCode(13,10) + clear_quotes(clear_html_code(rs_comment.replace('<br>',"r"))) + String.fromCharCode(13,10,13,10,13,10) + '--------------------------------------------' + String.fromCharCode(13,10) + '| Asesores del número |' + String.fromCharCode(13,10) + '--------------------------------------------' + String.fromCharCode(13,10) + rs_asesors.replace(/<br>/gi,"") + String.fromCharCode(13,10,13,10,13,10) + '--------------------------------------------' + String.fromCharCode(13,10) + '| Listado de artículos del número |' + String.fromCharCode(13,10) + '--------------------------------------------' + String.fromCharCode(13,10,13,10) + rs_articles_txt + String.fromCharCode(13,10,13,10,13,10) + '----------------------------------------------------------------------------------------------------------' + String.fromCharCode(13,10) + 'Director y Editor: Dr.C. Mikhail Benet Rodríguez --> [Correo Electrónico: [email protected]]' + String.fromCharCode(13,10) + 'Diseñador y Webmaster: Ing. Andry Rodríguez Pérez --> [Correo Electrónico: [email protected]]' + String.fromCharCode(13,10,13,10) + 'Visitenos en: http://medisur.cfg.sld.cu/' + String.fromCharCode(13,10) + '----------------------------------------------------------------------------------------------------------' + String.fromCharCode(13,10,13,10) + 'Aclaración!!! : Este mensaje no puede ser considerado como SPAM ya que el usuario solo lo recibe si se suscribió a nuestro servicio; además el usuario puede cancelar su suscripción accediendo al link: http://medisur.cfg.sld.cu/subs_baja.asp' + String.fromCharCode(13,10);
//
}


//-- Send text emails
counter = 0;
bcc = '';
if (To_t.length > 0)
{
for (h=0; h <= until_t ; h++)
{
if (counter == 8)
{
sendMail("169.158.166.216","[email protected]","Revista Medisur","Nueva publicación --- " + date_ ,body_text,'','text',0,bcc);
bcc = 0;
counter = 0;
} else {
bcc += To_t[h] + ';';
}
//Response.Write(To_t[h]+'<br>');
}
}
sendMail("169.158.166.216","[email protected]","Revista Medisur","Nueva publicación --- " + date_ ,body_text,'','text',0,bcc);
//--



//-- Send html emails
counter = 0;
bcc = '';
if (To_h.length > 0)
{
for (h=0; h <= until_h ; h++)
{
if (counter == 8)
{
sendMail("169.158.166.216","[email protected]","Revista Medisur","Nueva publicación --- " + date_ ,body_html,'','html',0,bcc);
bcc = 0;
counter = 0;
} else {
bcc += To_h[h] + ';';
}
//Response.Write(To_h[h]+'<br>');
}
}
sendMail("169.158.166.216","[email protected]","Revista Medisur","Nueva publicación --- " + date_ ,body_html,'','html',0,bcc);

//--> Esto esta comentado para ver el resultado que imprime la funcion sendmail, lo quitas cuando funcione.

if (errors != '')
{
%>
<form action="tool_send_public.asp" method="post" name="form1">
<input type="hidden" name="error" value="<%= errors %>">
</form>
//<script language="JavaScript">
document.form1.submit();
</script>
<%
} else {
%>

<script language="JavaScript">
document.form1.submit();
</script>

<%
}
}


}
save_log( '-- > Chequeado de envio de publicaciónes.', Session("Name"), Session("id"), 'chk_send_public.asp', Request.Form("error") );
%>
</body>
</html>
<% Conn.Close();%>

Esperando su ayuda