经典 ASP - 带有附加文件的电子邮件表单 - 请帮忙

发布于 2024-08-29 13:18:22 字数 974 浏览 3 评论 0原文

我遇到了一个问题,我有一个电子邮件网络表单,可以将输入发送到电子邮件地址,但我现在需要的是一个文件输入字段,用户还可以将图像作为附件发送。

所以联系人姓名、徽标(附件)。

有人告诉我,为了发送附件,需要将其保存在我的主机上的文件夹中,然后才能发送。我已经与托管公司交谈过,他们没有任何措施可以让这变得更容易,例如 aspupload。

以 name="contactname" 和 name="logo" 的形式,我在根目录中有一个名为 logos 的文件夹(此 asp 页面也存在于根目录中)

伙计,我希望有人可以帮助我花了很长时间寻找答案

Dim contactname, logo

contactname = request.form("contactname")
If request("contactname") <> "" THEN
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Form"
myMail.From="web@email"
myMail.To="web@email"
myMail.HTMLBody = "" & contactname & ""
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay.host"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing

Ive got abit of a problem ive got an email web form that send the input to an email address but what I now need is a file input field were the user can also send an image as an attachment.

So contact name, logo (attachment).

Ive been told in order to send the attachment it needs to be saved in a folder on my hosting before it can be sent. Ive spoken to the hosting company and they dont have anything in place to make this easier such as aspupload.

In the form name="contactname" and name="logo" I have a folder in the root directory called logos (this asp page also exists in the root directory)

Man I hope someone can help me spent along time looking for answers

Dim contactname, logo

contactname = request.form("contactname")
If request("contactname") <> "" THEN
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Form"
myMail.From="web@email"
myMail.To="web@email"
myMail.HTMLBody = "" & contactname & ""
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay.host"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紫南 2024-09-05 13:18:22

您不能根据从输入字段获取的位置的格式仅使用以下其中一项吗?您不必将其保存到服务器。

<% 
' ... 

myMail.AddAttachment Server.MapPath("file1.txt") 
myMail.AddAttachment "d:\file2.txt" 
myMail.AddAttachment "file://d:\file3.txt" 

' ...
%>

Can't you just use one of the following, depending on the format of the location you get from the input field? You shouldn't have to save it to the server.

<% 
' ... 

myMail.AddAttachment Server.MapPath("file1.txt") 
myMail.AddAttachment "d:\file2.txt" 
myMail.AddAttachment "file://d:\file3.txt" 

' ...
%>
书信已泛黄 2024-09-05 13:18:22

您需要使用文件输入控件。基本思想是这样声明您的表单:

<form method="POST" action="YourScript.asp" enctype="multipart/form-data">
<input name="ContactName" type="text" size="50">
<input name="LogoFile" type="file">
<input type="submit" value="Send">
</form>

然后 YourScript.asp 应该使用 ASP Upload 控件将上传的文件存储在服务器上的某个位置,然后使用 CDOSYS 的 AddAttachment 方法。

注意:使用此上传组件时,普通的Request.Form不再可用(由于调用了Response.BinaryRead)。您可以使用此上传控件的 Fields 集合来获取 ContactName 值。

这样的 ASP Upload 控件可以在这里找到:

http://www.asp101.com/ articles/jacob/scriptupload.asp

http ://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4

You need to use a file input control. The basic idea is that you declare your form like this:

<form method="POST" action="YourScript.asp" enctype="multipart/form-data">
<input name="ContactName" type="text" size="50">
<input name="LogoFile" type="file">
<input type="submit" value="Send">
</form>

YourScript.asp should then use an ASP Upload control to store the uploaded file somewhere on the server, and then use the AddAttachment method of CDOSYS.

Note: When using this upload component, the normal Request.Form is no longer available (due to Response.BinaryRead being called). You can get to the ContactName value by using the Fields collection of this upload control instead.

Such an ASP Upload control can be found here:

http://www.asp101.com/articles/jacob/scriptupload.asp

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4

年少掌心 2024-09-05 13:18:22

嗯,是的,如果文件已经存储,我可以使用上述之一,但它没有。该文件来自最终用户的电脑。

因此,他们单击表单中的浏览器并导航到计算机上的文件。我认为需要将其保存到我的主机上的文件中,然后插入文件位置,就像您所做的那样,以便发送它。

erm yeah I could use one of the above if the file was stored already but it not. The file is coming off the end users pc.

So they click browser in the form and navigate to the file on there pc. Which I think then needs to be saved to a file on my hosting then file location inserted kinda like you have done in order for it to be sent.

药祭#氼 2024-09-05 13:18:22

对于经典的asp,您需要首先以二进制数据形式上传文件:

Dim binaryData

要以二进制形式上传文件,只需谷歌,您将获得很多经典asp的解决方案。您可以访问:http://www.planet-source-code.com/vb/scripts /ShowCode.asp?txtCodeId=7361&lngWId=4

如果你点击上面的链接,它应该是:

Dim binaryData = objUpload("File1").BLOB & ChrB(0)

此后,你不需要将二进制数据存储在数据库中。只需创建一个记录集对象,如下所示:

 set rset = server.createobject("ADODB.RECORDSET")
 rset.fields.append "FileName", 205, LenB(binaryData)
 rset.open
 rset.addnew
 rset.fields(0).AppendChunk binaryData

然后您可以创建 CDO 消息对象并继续操作:

Set myMail=CreateObject("CDO.Message")
'//your mail code here
myMail.Configuration.Fields.Update

binaryData = rset.fields("FileName").value             
Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition"
Const cdoBase64 = "base64"            
Dim attach : Set attach = myMail.Attachments.Add            
attach.ContentMediaType = "application/octet-stream"
attach.ContentTransferEncoding = cdoBase64
'//Here I am just attaching an jpeg image file with fixed name 'myimage.jpg'
attach.Fields(cdoContentDisposition).Value="attachment;filename=""myimage.jpg"""
attach.Fields.Update
Dim oStreamOutput: Set oStreamOutput = attach.GetDecodedContentStream
oStreamOutput.Write binData
oStreamOutput.Flush
myMail.Send
set myMail=nothing

这样您无需将上传的文件存储在数据库或服务器空间中。您可以即时附加文件。希望有帮助。

For classic asp you need to first get file uploaded in binary data form:

Dim binaryData

For getting uploaded file in binary form just google and you shall get a lot of solutions for classic asp.You can go to for : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7361&lngWId=4

If you go by the above link, it shall be:

Dim binaryData = objUpload("File1").BLOB & ChrB(0)

Thereafter,you need not store the binary data in database.Just create a recordset object as given below:

 set rset = server.createobject("ADODB.RECORDSET")
 rset.fields.append "FileName", 205, LenB(binaryData)
 rset.open
 rset.addnew
 rset.fields(0).AppendChunk binaryData

Then you can create CDO message object and proceed as:

Set myMail=CreateObject("CDO.Message")
'//your mail code here
myMail.Configuration.Fields.Update

binaryData = rset.fields("FileName").value             
Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition"
Const cdoBase64 = "base64"            
Dim attach : Set attach = myMail.Attachments.Add            
attach.ContentMediaType = "application/octet-stream"
attach.ContentTransferEncoding = cdoBase64
'//Here I am just attaching an jpeg image file with fixed name 'myimage.jpg'
attach.Fields(cdoContentDisposition).Value="attachment;filename=""myimage.jpg"""
attach.Fields.Update
Dim oStreamOutput: Set oStreamOutput = attach.GetDecodedContentStream
oStreamOutput.Write binData
oStreamOutput.Flush
myMail.Send
set myMail=nothing

This way you need not store the uploaded file in database or to your server space.You can just attach the file on the fly. Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文