Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

lendadomato

[Resolvido] Upload de arquivos e envio p/email

Recommended Posts

Bom galera,

 

tenho um form em asp q recupera todos os campos, imprime esses campos na tela

e envia os dados para meu email e para o email do cliente, até aí tudo bem, mas

gostaria que o sistema enviasse os anexos para os emails, para imprimir na tela usei

um loop e deu certo, mas não vão para o email. Segue uma parte do font:

 

 

form.asp

 

<table width="100%" border="0">


<tr>
<td colspan="2">
<b>Deseja enviar algum arquivo?.</b>  <br><br>

<font face="Verdana, Arial, Helvetica, sans-serif" size="2">Anexo 1:
<input type="file" value="Anexo" name="file">
</font></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Anexo 2:
<input type="file" value="Anexo" name="file2">
</font></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Anexo 3:
<input type="file" value="Anexo" name="file3">
</font></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Anexo 4:
<input type="file" value="Anexo" name="file4">
</font></td>
</tr>
</table>

 

recebe.asp

 

<%
On Error Resume Next
Dim objUpload

Set objUpload = server.CreateObject("Dundas.Upload.2")

objUpload.UseVirtualDir = True

objUpload.UseUniqueNames = False

objUpload.Save "/arquivos"

%>

 

aqui eu imprimo na tela com um loop q tá certinho

 

<table width="800" border=2 cellspacing=0 cellpadding=2 bordercolor="999966">

<tr width="800" bgcolor="ffffff" bordercolor="ffffff">
<td width="800" align="left" valign="top">
<font color="#000000" size="1">
<b>Anexo(s):</b><br>

<%



For Each objUploadedFile in objUpload.Files

nomearquivo = objUpload.GetFileName(objUploadedFile.OriginalPath)

  
Response.Write("<A href='http://www.meusite.com/arquivos/" & nomearquivo & "'> " & nomearquivo & " </a>     ")
Next %>      


</font>
</td>
</tr>
</table>

 

aqui eu envio para o email

 


EnviaEmail Application("HostLoja"), Application("ComponenteLoja"), emailloja, " ", emailloja, "Orçamento de "&strNome&"",strMensagem%> 

 

aqui o sistema para envio

 

<%


Function EnviaEmail(Host,Componente,Email,NomeEmail,ParaEmail,Assunto,Mensagem)
Select Case Componente


Case "AspEmail"
	    on error resume next
	    Set eObjMail = Server.CreateObject("Persits.MailSender")
	    eObjMail.Host = Host
	 	eObjMail.From = Email
	 	eObjMail.FromName = NomeEmail
	 	eObjMail.AddReplyTo Email
	 	eObjMail.AddAddress ParaEmail
	    eObjMail.Subject = Assunto
          eObjMail.Attachments.Add = Anexo
	    eObjMail.isHTML = true
	 	eObjMail.Body = Mensagem	 	
	 	eObjMail.Send
	 	Set eObjMail = nothing

End Select
End Function
%>

 

como vou fazer para receber os anexos no email?

Desde já agradeço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Encontrei isso no manual do Dundas, veja se te ajuda:

 

The following source code demonstrates how to send an email along with a file attachment via an ASP page.

 

Files are uploaded by the user via file input elements in a form (with an EncType of "multipart/form-data"). Then the Dundas Upload Control is used to save uploaded files to disk. Once this is done we then iterate through all uploaded files via the Upload control's Files collection and add each file to the Mailer control's Attachments collection. Once all files have been added to this collection the email is sent with the SendMail method of the Mailer control.

 

Assumptions

 

A form with an ENCTYPE of "multipart/form-data" is POSTING data to this ASP page.

 

The form contains one or more file input elements (e.g. <input type="file" name="txtFile">

 

<%
Dim objUpload 'stores upload control instance
Dim objEmail 'stores mailer control instance
Dim strPath 'stores path of the asp page
Dim Index 'counter variable

'functions will throw an exception if not successful so On Error Resume Next is used for inline error trapping
On Error Resume Next

Set objUpload = Server.CreateObject("Dundas.Upload") 'Upload object
Set objEmail = Server.CreateObject("Dundas.Mailer") 'Mailer object

'create temporary directory to store uploaded files (if it doesn't already exist)
' at the same directory level as this asp page
strPath = Server.MapPath(".") & "\temp\"
objUpload.DirectoryCreate strPath

'save the uploaded files to the temp directory.
'doing this populates the Upload control's collections
'note that we could also save to memory with the SaveToMemory method
objUpload.Save strPath

'add an Address object to the TOs collection (this specifies the destination address)
objEmail.TOs.Add "someone@somewhere.com"

'specify the message subject
objEmail.Subject = "Some Subject"

'specify an SMTP server. Doing this increases the speed and reliability of the mail operation
objEmail.SMTPRelayServers.Add "somesmtpserver.com"

'set the message body
objEmail.Body = "This is the message body"

'now loop through all uploaded files (uploaded via file input boxes), and add
' each uploaded file to the Mail control's Attachments collection
'NOTE: you can use either a For Each loop or a standard For loop here
For Each Item in objUpload.Files
'Note: we are using the OriginalPath property of the UploadedFile object
' (which composes the Files collection) for the ContentName argument of each Attachment
' object. This lets the recipient of the email see the original filename of the attachment,
' (e.g. SomePicture.jpg) instead of the name by which the attachment was saved as. All files
' which are saved to disk have a GUID preceding the original filename used for unique identification.
objEmail.Attachments.Add Item.Path,Item.OriginalPath
Next

'now send the email
objEmail.SendMail

'test for success/failure of the SendMail operation using VBScript's Err object
If Err.Number <> 0 Then 
'an error occurred so output the relevant error string
Response.Write "The following error occurred: " & Err.Description
Else
'successful, so output a success message to user
Response.Write "The email was successfully forwarded to the specified SMTP server."
End If

Set objEmail = Nothing 'release resources
Set objUpload = Nothing
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Caro amigo Gutoffline,

 

valeu pela matéria, deu BINGOOOO!!!

 

Funcionou certinho, MUITO OBRIGADO.

 

 

 

 

Encontrei isso no manual do Dundas, veja se te ajuda:

 

The following source code demonstrates how to send an email along with a file attachment via an ASP page.

 

Files are uploaded by the user via file input elements in a form (with an EncType of "multipart/form-data"). Then the Dundas Upload Control is used to save uploaded files to disk. Once this is done we then iterate through all uploaded files via the Upload control's Files collection and add each file to the Mailer control's Attachments collection. Once all files have been added to this collection the email is sent with the SendMail method of the Mailer control.

 

Assumptions

 

A form with an ENCTYPE of "multipart/form-data" is POSTING data to this ASP page.

 

The form contains one or more file input elements (e.g. <input type="file" name="txtFile">

 

<%
Dim objUpload 'stores upload control instance
Dim objEmail 'stores mailer control instance
Dim strPath 'stores path of the asp page
Dim Index 'counter variable

'functions will throw an exception if not successful so On Error Resume Next is used for inline error trapping
On Error Resume Next

Set objUpload = Server.CreateObject("Dundas.Upload") 'Upload object
Set objEmail = Server.CreateObject("Dundas.Mailer") 'Mailer object

'create temporary directory to store uploaded files (if it doesn't already exist)
' at the same directory level as this asp page
strPath = Server.MapPath(".") & "\temp\"
objUpload.DirectoryCreate strPath

'save the uploaded files to the temp directory.
'doing this populates the Upload control's collections
'note that we could also save to memory with the SaveToMemory method
objUpload.Save strPath

'add an Address object to the TOs collection (this specifies the destination address)
objEmail.TOs.Add "someone@somewhere.com"

'specify the message subject
objEmail.Subject = "Some Subject"

'specify an SMTP server. Doing this increases the speed and reliability of the mail operation
objEmail.SMTPRelayServers.Add "somesmtpserver.com"

'set the message body
objEmail.Body = "This is the message body"

'now loop through all uploaded files (uploaded via file input boxes), and add
' each uploaded file to the Mail control's Attachments collection
'NOTE: you can use either a For Each loop or a standard For loop here
For Each Item in objUpload.Files
'Note: we are using the OriginalPath property of the UploadedFile object
' (which composes the Files collection) for the ContentName argument of each Attachment
' object. This lets the recipient of the email see the original filename of the attachment,
' (e.g. SomePicture.jpg) instead of the name by which the attachment was saved as. All files
' which are saved to disk have a GUID preceding the original filename used for unique identification.
objEmail.Attachments.Add Item.Path,Item.OriginalPath
Next

'now send the email
objEmail.SendMail

'test for success/failure of the SendMail operation using VBScript's Err object
If Err.Number <> 0 Then 
'an error occurred so output the relevant error string
Response.Write "The following error occurred: " & Err.Description
Else
'successful, so output a success message to user
Response.Write "The email was successfully forwarded to the specified SMTP server."
End If

Set objEmail = Nothing 'release resources
Set objUpload = Nothing
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

a apresentação dos dados no email ficou show de bola, mas

tem sempre um detalhe, corpo do html está vindo redondinho

usando <META content='text/html; charset=iso-8859-1' http-equiv=Content-Type>

 

o problema é o assunto, ele vem sem acentuação

 

o meu form já é configurado para receber o form de "Orçamento" e dessa forma

no assunto do email fica: "Orgamento" e se tiver caracteres especiais a coisa fica preta.

Bom, o q tenho é isso:

 

 

objEmail.Subject = "Orçamento de Camisetas!"

 

 

espero ter sido claro!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.