首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jmail经典ASP上传文件和发送

Jmail经典ASP上传文件和发送
EN

Stack Overflow用户
提问于 2017-09-19 03:43:22
回答 1查看 747关注 0票数 0

我想知道如何上传一个文件和发送邮件使用经典ASP和Jmail,我想选择文件使用HTML。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-19 09:51:33

在这里,你有两件事要解决--上传文件,并将其附加到出站电子邮件中。

您可能需要第三方上传组件--许多Windows托管公司已经准备好了ASP组件的“Persit”套件,以便与工作演示一起使用。这是您自己的服务器还是共享的主机等等?因为可能会影响共享主机与您实际可以做的-例如最大文件大小,文件类型等。

示例代码应该会对您有所帮助,但请注意,“组分”部分显然需要与您使用的任何内容保持一致。

上传-发送附有附件的电子邮件

代码语言:javascript
复制
 <%     'Sample file Form-Email.asp      ' Let's you send one an email with one or more attachments.
代码语言:javascript
复制
'Create upload form
Dim Form: Set Form = Server.CreateObject("SomeComponent.ASPForm")

'Do not upload data greater than 1MB. 
Form.SizeLimit = 100*1024

Const fscompleted  = 0

If Form.State = fscompleted Then 'completed
  ProcessForm
End If 


Sub ProcessForm
  Dim eFrom, eTo, Subject, Message

  'get source form fields - From, To, Subject and Message
  eFrom = Form("From")
  eTo = Form("To")
  Subject = Form("Subject")
  Message = Form("Message")

  Dim objNewMail, File, FileName, FS, TempFolder

  Set FS = CreateObject("Scripting.FileSystemObject")
  'Get temporary folder
  TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"

  'Create a new email message
  Set objNewMail = CreateObject("CDONTS.NewMail")
  Const CdoMailFormatMime = 0
  objNewMail.MailFormat = CdoMailFormatMime
  'Save source files to temporary folder
  'Add these files to the new e-mail
  For Each File In Form.Files
    'If source file is specified.
    If Len(File.FileName) > 0 Then
      FileName = TempFolder & "\" & File.FileName 

      File.SaveAs FileName

      objNewMail.AttachFile FileName
    End If
  Next

  'Send the new email
  objNewMail.Send eFrom, eTo, Subject, Message

  'delete temporary files
  For Each File In Form.Files
    If Len(File.FileName) > 0 Then
      FileName = TempFolder & "\" & File.FileName 
      FS.DeleteFile FileName
    End If
  Next
End Sub

%>  
<br>Sample For <A Href=http://www.motobit.com>HugeASP upload</A>
<br> Let's you send one an email with one or more attachments.
<br> File size limit Is <%=Form.SizeLimit%> B (<%=Form.SizeLimit \ 1024 %>kB).
<Table Border=0>
<form method="POST" ENCTYPE="multipart/form-data">
  <tr><td> From : </td><td><input Name=From Size=50></td></tr>

  <tr><td> To : </td><td><input Name=To Size=50></td></tr>

  <tr><td> Subject : </td><td><input Name=Subject Size=80></td></tr>

  <tr><td ColSpan=2> Message:
    <br><TextArea Name=Message Cols=76 Rows=10></TextArea>
  </td></tr>

  <tr><td ColSpan=2>E-Mail Attachments:
    <Div ID=files>
       Attachment 1 : <input type="file" name="File1">
    </Div>
    <Input Type=Button Value="Add a file" OnClick=return(Expand()) 
     Style="border=0;background=yellow;cursor:hand">
  </td></tr>

  <tr><td ColSpan=2 Align=Right>
    <input Name=SubmitButton Value="Send email >>" Type=Submit></td></tr>
  </Form>
</Table>

<Script>
//Script To add a attachment file field 
var nfiles = 1;
Function Expand(){
  nfiles++
  var adh = '<BR> Attachment '+nfiles+' : <input type="file" 
 name="File'+nfiles+'">';
  files.insertAdjacentHTML('BeforeEnd',adh);
  return false;
}
</Script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46291429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档