Asohk.com
Would you like to react to this message? Create an account in a few clicks or log in to continue.

ASP/ASP.NET: Upload file and attach it to email

Go down

ASP/ASP.NET: Upload file and attach it to email Empty ASP/ASP.NET: Upload file and attach it to email

Post  Admin Sat Aug 02, 2008 12:06 pm

Introduction

I found lots of web pages to explain how to email an attachment (already on the server) and lots showing upload, but no integrated examples using ASPUpload, which was the preferred technology for my web host. Here it is, to save the next guy the headache.
[edit]
Steps

This solution uses four ASP pages - initial and action page for the email, and inside an iframe, initial and action pages for the upload.


[edit]
Examples

parent page snippet:
<iframe src="supp_service_request_upload.asp" height=60 width=380 scrolling="no" frameborder="0" id="attachmentFrame" name="attachmentFrame"></iframe>
<input type="hidden" value="" name="attachmentFilePath" id="attachmentFilePath">


iframe initial page (complete):
<HTML>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="supp_service_request_upload_action.asp">
<input name="FILE1" id="FILE1" size="45" type="file">
<INPUT TYPE=SUBMIT VALUE="Upload File">
</FORM>
</BODY>
</HTML>


iframe action page (complete) - note that you need to double the slashes for the JavaScript:
<HTML>
<BODY>
<%@ Language=VBScript %>
<% Set Upload = Server.CreateObject("Persits.Upload.1")
Count = Upload.SaveVirtual("upload") %>
<% = Count %> files uploaded.

<script language="javascript1.2">
<%
For Each File in Upload.Files
uploadedFilePath = File.Path
uploadedFilePath=Replace(uploadedFilePath, "\", "\\")
Response.Write "parent.window.document.getElementById('attachmentFilePath').value='" & uploadedFilePath & "';"
Next
%>
</script>
</BODY>
</HTML>


parent page action snippet - note you need to un-double the slashes for the ASP, and then delete the file from the server:

<%@ Language=VBScript %>
<%
emailFrom=Request("username")
problemDesc=Request("wassaMatta")
serialNumber=Request("serialNum")
probType=Request("probType")
attachFile=Request("attachmentFilePath")
attachFile=Replace(attachFile, "\\", "\")
emailBody=[code trimmed]

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Website Customer"
Mailer.FromAddress= emailFrom
Mailer.RemoteHost = "smtp.thermawave.com"
Mailer.AddRecipient "TWAV Support", "[code trimmed]"
Mailer.Subject = "Customer Support Request from [code trimmed]:"
Mailer.AddAttachment(attachFile)
Mailer.BodyText = emailBody

emailSendResults = "Thank you. Your request has been submitted to Support.

You will receive a verification email soon."
if not Mailer.SendMail then
emailSendResults = "Mail send failure. Error was " & Mailer.Response
else
set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile(attachFile)
end if
set Mailer = Nothing
%>
Admin
Admin
Admin
Admin

Posts : 60
Join date : 2007-12-17

https://asohk.forummotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum