【问题标题】:Jmail Classic ASP upload file and sendJmail Classic ASP 上传文件并发送
【发布时间】:2017-09-19 03:43:22
【问题描述】:

我想知道如何使用 Classic ASP 和 Jmail 上传文件并通过邮件发送,我想使用 HTML type=file 选择文件。

【问题讨论】:

  • 你能在这里添加你的代码吗?让我们知道您遇到了什么问题?

标签: html email asp-classic jmail


【解决方案1】:

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

您可能需要第三方上传组件 - 许多 Windows 托管公司都有“Persits” ASP 组件套件,可用于工作演示。 这是您自己的服务器还是共享主机等?因为共享主机可能会对您实际可以做的事情产生影响 - 例如最大文件大小、文件类型等。

示例代码应该对您有所帮助,但请注意“somecomponent”位显然需要与您使用的任何内容内联。

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

'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>

【讨论】:

  • 非常感谢,我会尝试实现这些代码并在我们自己的服务器中测试它们(我们托管 Web 服务器和邮件服务器)。
  • OP 说他正在使用 Jmail,但无论如何我不会再推荐使用 CDONTS,它不包含在 Windows Server 2003 或此后的任何版本中。 CDOSYS 是当前版本的默认邮件组件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
相关资源
最近更新 更多