|
<%@Language="VBScript" Codepage = 65001%> |
|
<% |
|
Option Explicit |
|
Response.CodePage = 65001 |
|
Response.Charset = "UTF-8" |
|
|
|
Dim pde : Set pde = Server.CreateObject("scripting.dictionary") |
|
|
|
Function getTextFromFile(path) |
|
Dim adoStream, txt |
|
Set adoStream = Server.CreateObject("ADODB.Stream") |
|
Call adoStream.Open() |
|
adoStream.Charset = "UTF-8" |
|
Call adoStream.LoadFromFile(path) |
|
txt = adoStream.ReadText(-1) |
|
Call adoStream.Close() |
|
Set adoStream = Nothing |
|
getTextFromFile = txt |
|
End Function |
|
|
|
Dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode |
|
redir = Request.Form("redirect") |
|
mailto = Request.Form("mailto") |
|
If pde.exists(mailto) Then mailto = pde(mailto) |
|
|
|
subject = Request.Form("subject") |
|
message = Request.Form("message") |
|
template = Request.Form("template") |
|
|
|
If Len(template) > 0 Then template = getTextFromFile(Server.MapPath(template)) |
|
usetemplate = (Len(template) > 0) |
|
|
|
Dim msg : Set msg = Server.CreateObject("CDO.Message") |
|
Dim smtpServer, yourEmail, yourPassword |
|
|
|
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 |
|
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" |
|
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 |
|
Call msg.Configuration.Fields.Update() |
|
|
|
msg.Subject = "Test Email" |
|
msg.To = "someone@example.com" |
|
msg.From = "theserver@example.com" |
|
|
|
If Len(cc) > 0 Then msg.cc = cc |
|
If Len(bcc) > 0 Then msg.bcc = bcc |
|
|
|
If Not usetemplate Then |
|
body = body & message & vbCrLf & vbCrLf |
|
Else |
|
body = template |
|
End If |
|
|
|
For Each item In Request.Form |
|
Select Case item |
|
Case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode" |
|
Case Else |
|
If Not usetemplate Then |
|
If item <> "mailfrom" Then body = body & item & ": " & Request.Form(item) & vbCrLf & vbCrLf |
|
Else |
|
body = replace(body, "[$" & item & "$]", Replace(Request.Form(item), vbCrLf, "<br>")) |
|
End If |
|
End Select |
|
Next |
|
|
|
If usetemplate Then |
|
Dim rx : Set rx = New RegExp |
|
rx.Pattern = "\[\$.*\$\]" |
|
rx.Global = True |
|
body = rx.Replace(body, "") |
|
End If |
|
|
|
msg.BodyPart.Charset = "utf-8" |
|
msg.htmlbody = body |
|
|
|
Call msg.Send() |
|
%> |