Foros del Web » Programando para Internet » ASP Clásico »

envio de email

Estas en el tema de envio de email en el foro de ASP Clásico en Foros del Web. hola amigos tengo un problema con un envio de email, bueno ya hechos envios de email desde otros servidor pero varia segun los servicios q ...
  #1 (permalink)  
Antiguo 09/08/2006, 09:46
 
Fecha de Ingreso: enero-2006
Mensajes: 233
Antigüedad: 18 años, 5 meses
Puntos: 2
envio de email

hola amigos tengo un problema con un envio de email, bueno ya hechos envios de email desde otros servidor pero varia segun los servicios q te da el servidor,
quiero poner una forma sencilla pero segun las indicaciones de godaddy debo mandar mi forma al archivo gdform.asp q lo tiene el mismo servidor
el ejemplo q me dan es este
<form action="gdform.asp" method="post">
<input type="hidden" name="subject" value="Form Submission" />
<input type="hidden" name="redirect" value="thankyou.html" />
<p>First Name:<input type="text" name="FirstName" /></p>
<p>Last Name:<input type="text" name="LastName" /></p>
<p>E-Mail:<input type="text" name="email" /></p>
<p>Comments:<textarea name="comments" cols="40" rows="10">
Type comments here.</textarea></p>
<input type="submit" name="submit" value="submit"/>
</form>

y el codigo del el gdform.asp es este
<%

Dim landing_page, host_url
Dim fso, outfile, filename, dirname, myFolder
Dim req_method, key, value
Dim bErr, errStr, bEmpty
On Error resume next
bErr = false
bEmpty = true
errStr = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
host_url = Request.ServerVariables("HTTP_HOST")
req_method = Request.ServerVariables("REQUEST_METHOD")
dtNow = Now()
filename = Server.MapPath("ssfm")
dirname = filename
filename = filename & "/gdform_" & DatePart("M", dtNow) & DatePart("D", dtNow) & DatePart("YYYY", dtNow) & DatePart("N", dtNow) & DatePart("S", dtNow)

Function FormatVariableLine(byval var_name, byVal var_value)
Dim tmpStr
tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " START>" & vbCRLF
tmpStr = tmpStr & var_value & vbCRLF
tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " END>"
FormatVariableLine = tmpStr
end function

Sub OutputLine(byVal line)
outfile.WriteLine(line)
end sub

if err.number = 0 then
Set outfile = fso.CreateTextFile(filename, true, false)
if err.number <> 0 then
bErr = true
errStr = "Error creating file! Directory may not be writable or may not exist.<br>Unable to process request."
else
if(req_method = "GET") then
for each Item in request.QueryString
if item <> "" then
bEmpty = false
key = item
value = Request.QueryString(item)
if(lcase(key) = "redirect") then
landing_page = value
else
line = FormatVariableLine(key, value)
Call OutputLine(line)
end if
end if
next
elseif (req_method = "POST") then
for each Item in request.form
if item <> "" then
bEmpty = false
key = item
value = Request.form(item)
if(lcase(key) = "redirect") then
landing_page = value
else
line = FormatVariableLine(key, value)
Call OutputLine(line)
end if
end if
next
end if
outfile.close
end if
if(bEmpty = true) AND errStr = "" then
bErr = true
errStr = errStr & "<br>No variables sent to form! Unable to process request."
end if
if(bErr = false) then
if (landing_page <> "") then
response.Redirect "http://" & host_url & "/" & landing_page
else
response.Redirect "http://" & host_url
end if
else
Response.Write errStr
end if
set fso = nothing
else
Response.Write " An Error Occurred creating mail message. Unable to process form request at this time."
end if
%>
sin embargo no se como recoger los datos de las formas
supuestamente me sale q se envio pero no se envia nada
porfavor si me ayudan como aser el request en el gdform.asp se lo agradesco
garcias
saludos,
  #2 (permalink)  
Antiguo 09/08/2006, 10:35
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 18 años
Puntos: 1
Enviar un formulario por email con ASP

Hola nancy8120, aqui te pongo este codigo con algunas notas, espero te ayude.

Código:
<% 
if request.form="" then 
'no recibo formulario, entonces lo muestro 
%> 
<form action="formulario_mail_asp.asp" method="POST"> 
Nombre: <input type="Text" name="nombre" size="12" maxlength="200"> 
<br> 
Email: <input type="Text" name="email" size="12" maxlength="200"> 
<br> 
<input type="submit" value="Enviar"> 
</form> <% 
else 
'si que recibo un formulario, entonces lo trato 
'recojo los datos 
nombre = request.form("nombre") 
email = request.form("email") 
'compongo el cuerpo del mensaje 
cuerpo = "Formulario recibido" & VBNEWLINE & VBNEWLINE 
cuerpo = cuerpo & "Nombre: " & nombre & VBNEWLINE 
cuerpo = cuerpo & "Email: " & email 
'mando el correo... 
'.................. 
response.write "Gracias por rellenar el formulario. Se ha enviado correctamente." end if %>
En el anterior script utilizamos if (request.form="") para saber si estamos recibiendo o no información de un formulario.
Si no hemos recibido nada (porque en request.form tenemos una cadena vacía) este if saldría por su caso verdadero, en el que tendremos que presentar el formulario en la página.
El caso else, cuando sí que recibíamos un formulario, recogemos sus datos y creamos el cuerpo del mail que enviaremos a la dirección del administrador.
El resto del código, utilizado para definir las propiedades del email y enviarlo, todavía no lo hemos indicado. Antes una aclaración.
ASP no tiene entre las funciones del lenguaje una que sirva para enviar correos electrónicos. Sin embargo, podemos utilizar un componente ActiveX del servidor para realizar esas acciones.

El código para enviar un mail podría ser algo como esto:
Código:
'creo el objeto correo
set mail = server.createObject("Persits.MailSender") 
'configuro el mensaje 
'señalo el servidor de salida para enviar el correo 
mail.host = "mail.tudominio.com" 
'indico la dirección de correo del remitente 
mail.from = "[email protected]" 
'indico la dirección del destinatario del mensaje 
mail.addAddress "[email protected]" 
'indico el cuerpo del mensaje 
mail.body = cuerpo 
'lo envio 
'aseguro que no se presenten errores en la página si se producen 
On Error Resume Next 
mail.send 
if Err ><0 then 
response.write "Error, no se ha podido completar la operación" 
else 
response.write "Gracias por rellenar el formulario. Se ha enviado correctamente." end if
Espero te ayude esto, hasta la proxima.
  #3 (permalink)  
Antiguo 09/08/2006, 10:42
 
Fecha de Ingreso: enero-2006
Mensajes: 233
Antigüedad: 18 años, 5 meses
Puntos: 2
ok, voy a provarlo pero ya intente con Persits.MailSender y me manda un error de q el componente no esta istalado en el servidor
te informo luego
  #4 (permalink)  
Antiguo 09/08/2006, 10:57
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 18 años
Puntos: 1
El componente CDONTS (presente en muchas de las instalaciones de IIS) serviría para realizar el envío del mail, pero también existen en el mercado otros componentes de servidor comerciales para realizar esas acciones con mayores funcionalidades. Uno de ellos es AspEmail, es el que se utiliza en ese script, pero no es el único.

Verifica si el IIS esta instalado correctamente,si los componentes aun no han sido instalados ahi esta la base de nuestro problema.
Inicio>>>Panel de control>>>Agregar o quitar programas>>>Agregar o quitar componentes de windows>>>{palomear}Servicios der Internet Infomation Server (IIS){esta opcion contiene subopciones, asi q tendras q abrirla y palomear todos los componente que encuentres en ella}. Te mandare otras formas de mandar mail.
  #5 (permalink)  
Antiguo 09/08/2006, 11:10
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 18 años
Puntos: 1
continuamos con el mail

Aquí te pongo un codigo que encontre, hace unos meses lo utilice para el envio de formulario via mail.

forma.htm
Código:
<html>
<head>
<title>Forma de Cont&aacute;cto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form" method="post" action="forma.asp">
  <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr valign="top"> 
      <td width="95" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Nombre:</font></b></div>
      </td>
      <td width="161" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <input type="text" name="nombre" size="20" maxlength="50">
          </font></b></div>
      </td>
      <td width="74" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">E-Mail: 
          </font></b></div>
      </td>
      <td width="170" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <input type="text" name="correo" size="20" maxlength="50">
          </font></b></div>
      </td>
    </tr>
    <tr valign="top"> 
      <td width="95" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Empresa:</font></b></div>
      </td>
      <td width="161" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <input type="text" name="empresa" size="20" maxlength="50">
          </font></b></div>
      </td>
      <td width="74" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Tel&eacute;fono:</font></b></div>
      </td>
      <td width="170" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <input type="text" name="telefono" size="20" maxlength="50">
          </font></b></div>
      </td>
    </tr>
    <tr valign="top"> 
      <td width="95" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Asunto:</font></b></div>
      </td>
      <td colspan="3" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <select name="asunto">
            <option>Sugerencia</option>
            <option>Comentario</option>
            <option>Queja</option>
            <option>Cotizacion</option>
            <option selected>Seleccione...</option>
          </select>
          </font></b></div>
      </td>
    </tr>
    <tr valign="top"> 
      <td width="95" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Comentarios:</font></b></div>
      </td>
      <td colspan="3" height="34"> 
        <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
          <textarea name="comentarios" cols="45" rows="3"></textarea>
          </font></b></div>
      </td>
    </tr>
    <tr valign="top"> 
      <td colspan="4" height="34"> 
        <div align="center"><br>
          <input type="submit" name="envia" value="Enviar Forma">
          <input type="reset" name="borrar" value="Borrar Datos">
        </div>
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
forma.asp
Código:
<%
'Modificar este valor con su direccion de correo a la que se enviara el formulario
	var_destinatario = "[email protected]"
'No es necesario modificar el codigo restante

'Creacion de variables para almacenar los campos del formulario
	var_nombre = Request.Form("nombre")
	var_correo = Request.Form("correo")
	var_empresa = Request.Form("empresa")
	var_telefono = Request.Form("telefono")
	var_asunto = Request.Form("asunto")
	var_comentarios = Request.Form("comentarios")

'Creacion del cuerpo del mensaje
	var_mensaje = "Mensaje enviado desde el formulario web: " & nombre & chr(10) & chr(10)_
			& "Nombre: " & var_nombre & chr(10)_
			& "Empresa: " & var_empresa & chr(10)_
			& "Telefono: " & var_telefono & chr(10)_
			& "Correo Electronico: " & var_correo & chr(10) & chr(10)_
			& "Asunto: " & var_asunto & chr(10)_
			& "Comentarios: " & var_comentarios

'Procesamiento del envio de correo
	Set Mailer = Server.CreateObject("CDONTS.NewMail")
	Mailer.From = var_nombre & "<" & var_correo & ">"
	Mailer.To = var_destinatario
	Mailer.Subject = var_asunto
	Mailer.Body = var_mensaje
	Mailer.BodyFormat = 1
	Mailer.MailFormat = 1
	Mailer.Importance = 2
	Mailer.Send
	set Mailer = nothing
%>
<html>
<head>
<title>Gracias por sus Comentarios</title>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
  <p><font face="Verdana, Arial, Helvetica, sans-serif" size="4" color="#0000FF"><b>Gracias 
    por enviarnos sus comentarios.</b></font></p>
  <p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Nos pondremos 
    en contacto con usted a la brevedad.</font></p>
</div>
</body>
</html>
Saludos, luego avisas que pasa con eso.
  #6 (permalink)  
Antiguo 09/08/2006, 12:11
 
Fecha de Ingreso: enero-2006
Mensajes: 233
Antigüedad: 18 años, 5 meses
Puntos: 2
muchas gracias la verdad nunca e palomeado en las subopciones eso me puede ser de gran ayuda;
por otra parte encontre este script en internet y me funciono muy bien
con execion del upload me manda error la linea 82,
si tienes una opinion, ok
<%
' This is coded by [email protected]
'using the upload.asp example from asp101.com
' and combining it with the mail object to allow
' you upload a pic from your pc and email to anyone anywhere
' at anytime maybe it should be called martini mail
Response.Buffer = true
Function BuildUpload(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Conte nt-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filen ame="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),Requ estBin,boundary)
Loop
End Function

Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function

Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function

If request("Action")="1" then
Response.Clear
byteCount = Request.TotalBytes

RequestBin = Request.BinaryRead(byteCount)

Set UploadRequest = CreateObject("Scripting.Dictionary")

BuildUpload(RequestBin)

If UploadRequest.Item("blob").Item("Value") <> "" Then

contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
FolderName = UploadRequest.Item("where").Item("Value")
'Response.Write "FolderName: " & FolderName & "<BR>"
Path = Mid(Request.ServerVariables("PATH_TRANSLATED"), 1, Len(Request.ServerVariables("PATH_TRANSLATED")) - Len(Request.ServerVariables("PATH_INFO"))) & "\"
'Response.Write "Path:" & Path & "<BR>"
ToFolder = Path & "\" & FolderName
value = UploadRequest.Item("blob").Item("Value")
filename = ToFolder & "\" & filename
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = MyFileObject.CreateTextFile(filename)
'Response.Write "Saved Path: " & filename
For i = 1 to LenB(value)
objFile.Write chr(AscB(MidB(value,i,1)))
Next
objFile.Close
Set objFile = Nothing
Set MyFileObject = Nothing
End If
' ge the other form elements now
MySubject = UploadRequest.Item("MySubject").Item("Value")
MyTo = UploadRequest.Item("MyTo").Item("Value")
MyText = UploadRequest.Item("MyText").Item("Value")
MyFrom = UploadRequest.Item("MyFrom").Item("Value")
Set UploadRequest = Nothing
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
ObjCDOMail.From = MyFrom
ObjCDOMail.To = MyTo
ObjCDOMail.BodyFormat = 0
ObjCDOmail.Mailformat = 0
ObjCDOMail.Subject = MySubject
ObjCDOMail.Body = MyText
'heres an if statement to chk for an attachment
' I am sure theres another way but this does the job fine
If Len(filename) > 5 then
objCDOMail.AttachFile filename,nikfile
end if
ObjCDOMail.Send
Set ObjCDOMail = Nothing

Response.Write "your mail has been sent"
End If%>
<html>
<head>
<title>Anon Mail</title>
<!--
' This is coded by [email protected]
'using the upload.asp example from asp101.com
' and combining it with the mail object to allow
' you upload a pic from your pc and email to anyone anywhere
' at anytime maybe it should be called martini mail
-->
<style>
.text { font-family: Verdana,Arial;
color: black;
Font-size: 10pt
}
</style>
</head>
<body><form METHOD="POST" ENCTYPE="multipart/form-data" action="mailattachment.asp?Action=1" name="mailform" id="mailform">
<table border="0" align="center" width="350">
<tr>
<td class="text" colspan="2">
<h3>Send an Email to anyone with an attachment</h3>
</td>
</tr>
<tr>
<tr>
<td class="text" align="left">From</td>
<td class="text" align="right"><input class="text" type=text name=MyFrom size="30"></td>
</tr>
<tr>
<td class="text" align="left">To:</td>
<td align="right"><input class="text" name="MyTo" size="30"></td>
</tr>
<tr>
<td class="text" align="left">Subject:</td>
<td align="right"><input class="text" type=text name=MySubject size="30"></td>
</tr>
<tr>
<td class="text" colspan="2">Enter your email text below</td>
</tr>
<tr>
<td class="text" colspan="2" align="right"><textarea class="text" rows="7" name="MyText" cols="65"></textarea></td>
</tr>
<tr>
<td colspan="2" class="text" align="center">
Attach a file: <input TYPE="file" NAME="blob" value>
<input TYPE="HIDDEN" NAME="where" value="images">
<!-- change the value of this hidden field to change the directory of where uploads are stored-->
</td>
</tr>
<tr>
<td colspan="2" class="text">
<input class="text" type="submit" Value="Send it!" id=submit1 name=submit1></td>
</tr>
<tr>

</tr>
</table>
</form>
</body>
</html>


y muchas gracias por lo de palomear en los componente de IIS, creo q ese sera otro tema
saludos
  #7 (permalink)  
Antiguo 10/08/2006, 08:39
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 18 años
Puntos: 1
Hola nancy8120, aqui continuamos verificando.
La verdad corri tu codigo y no encontre problema, a lo mejor el unico problema que se pueda dar es este:

La configuración debe ser igual a la proporcionada por su administrador de red de área local (LAN) o su proveedor de servicios Internet (ISP).

Pura cosa de configurar bien la red, pero mas problemas no encuentro, de todas maneras continua informando del error y dudas para checar mas a fondo, estamos en contacto, siento no ser de mucha ayuda por el momento.

Saludas, y felices codigos.
  #8 (permalink)  
Antiguo 10/08/2006, 08:39
 
Fecha de Ingreso: enero-2006
Mensajes: 233
Antigüedad: 18 años, 5 meses
Puntos: 2
Hola para aclarar ok todos estos ejemplos son validos, pero en godaddy ya esta todo programado para el envio de email, me di cuenta un poco tarde despues de varios intentos, solo se hace la forma y se envia al gdform.asp y se especifica el email que va a recibir los mail en el panel de adminstracion del servidor
bye
  #9 (permalink)  
Antiguo 10/08/2006, 08:46
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 18 años
Puntos: 1
En horabuena y felicidades.

Como ya te habia mencionado.

Cita:
La verdad corri tu codigo y no encontre problema
Que bien por ti, ya me esta preocupando por que no salia, felicidades y continua esforzandote y participando en el foro.
  #10 (permalink)  
Antiguo 04/09/2006, 16:02
 
Fecha de Ingreso: junio-2006
Mensajes: 61
Antigüedad: 18 años
Puntos: 2
Pregunta

Quisiera saber si alguno de ustedes me puede ayudar en una duda, resulta que tengo alojamiento gratuito en 1asphost.com y lo que quiero saber es si hay algun componente para enviar mail gratuito, y si influye en algo que el hosting sea gratuito para el correcto funcionamiento del envio del mail.


saludos y anticipadamente Gracias!!!


Camilo ospina
Bogotá - Colombia
  #11 (permalink)  
Antiguo 04/09/2006, 16:36
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Cita:
Can I use CDONTS?

CDONTS will not work on our servers because it requires the web server to be running SMTP, and we do not run mail services on our web servers, only on our mail servers. This is done for both performance and security reasons.
Tendras que cambiarte de host (o pagar 9 dolares al mes), en las respuestas anteriores hay algunos buenos aportes.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:00.