Difference between revisions of "ASP Mail"
From KOP KB
(→Full Script) |
|||
Line 172: | Line 172: | ||
end if | end if | ||
end if | end if | ||
+ | %> | ||
+ | </syntaxhighlight> | ||
+ | == CDO MAIL SEPARATE FORMAT == | ||
+ | <syntaxhighlight lang="asp" enclose="div"> | ||
+ | <% | ||
+ | Dim objCDOMail | ||
+ | Set objCDOMail = Server.CreateObject("CDONTS.NewMail") ' Create instance of NewMail object. | ||
+ | |||
+ | Dim strBody | ||
+ | strBody = "Opening line of email:" & vbCrLf & vbCrLf | ||
+ | |||
+ | strBody = strBody & "Name: " & Request.Form("name") & vbCrLf | ||
+ | strBody = strBody & "Address: " & Request.Form("address") & vbCrLf | ||
+ | strBody = strBody & "City: " & Request.Form("city") & vbCrLf | ||
+ | strBody = strBody & "State: " & Request.Form("state") & vbCrLf | ||
+ | strBody = strBody & "Zip: " & Request.Form("zip2") & vbCrLf | ||
+ | strBody = strBody & "Day-Phone: " & Request.Form("Day_Phone") & vbCrLf | ||
+ | strBody = strBody & "Biz-Phone: " & Request.Form("Biz_Phone") & vbCrLf | ||
+ | strBody = strBody & "Email: " & Request.Form("email") & vbCrLf | ||
+ | strBody = strBody & "Birth-Day: " & Request.Form("birth_day") & vbCrLf | ||
+ | strBody = strBody & "Educational History: " & Request.Form("Educational_History") & vbCrLf | ||
+ | strBody = strBody & "Interested in Attending: " & Request.Form("interested_in_attending") & vbCrLf | ||
+ | strBody = strBody & "Course of Study: " & Request.Form("Course_of_Study") & vbCrLf | ||
+ | strBody = strBody & "Start-Date: " & Request.Form("Start_Date") & vbCrLf | ||
+ | strBody = strBody & "Best-Time: " & Request.Form("Best_Time") & vbCrLf | ||
+ | strBody = strBody & "Comments: " & Request.Form("q") & vbCrLf | ||
+ | strBody = strBody & "-----------------------------------------------" | ||
+ | |||
+ | objCDOMail.From = "CompanyName <[email protected]>" | ||
+ | objCDOMail.To = "[email protected]" | ||
+ | objCDOMail.Subject = "Subject" | ||
+ | objCDOMail.Body = strBody | ||
+ | |||
+ | objCDOMail.Send | ||
%> | %> | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 18:44, 31 March 2015
This is more of a testing script for trying out different types of email there are you can try through asp.
CDO
elseif u_method ="CDOSYS" then
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "localhost"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = s_from
.To = u_email
.Subject = "Testing email"
.TEXTBody = "CDOSYS aka CDO.Message worked"
.send
End With
Response.write "To: " & u_email
Response.write "From: " & s_from
Set cdoMessage = Nothing
Set cdoConfig = Nothing
CDONTS
elseif u_method = "CDONTS" then
Dim MyBody
Dim MyCDONTSMail
Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
MyCDONTSMail.From= s_from
MyCDONTSMail.To= u_email
MyCDONTSMail.Subject="This is a Test"
MyBody = "testing email" & vbCrLf
MyBody = MyBody & "CDONTS seems fine" & vbCrLf
MyCDONTSMail.Body= MyBody
MyCDONTSMail.Send
set MyCDONTSMail=nothing
Response.write "To: " & u_email
Response.write "From: " & s_from
ASPMAIL AND QMAIL
if u_method = "ASPMAIL" or u_method = "QMAIL" then
set Mailer = Server.CreateObject("SMTPsvg.Mailer")
if u_method = "QMAIL" then
'This is pretty much setting qmail right here
'if its not set then pretty much its aspmail sending it
Mailer.QMessage = "true"
Mailer.Subject = "Testing ASPQmail"
else
Mailer.Subject = "Testing ASP Mail"
end if 'ASPQMAIL
Mailer.FromName = "Test"
Mailer.FromAddress= s_from
Mailer.RemoteHost = "localhost"
Mailer.AddRecipient "Test",u_email
Mailer.BodyText = "This is a Test"
Mailer.SMTPLog = server.mappath("./smtp.log")
if Mailer.SendMail then
Response.write "To: " & u_email
Response.write "From: " & s_from
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if 'sendmail success
Full Script
<form action=mailtest.asp method=post>
<div>Enter the email you would like to send to: <input type=text name=email> using the mailer:
<select name=mailobject>
<option value="CDONTS">CDONTS</option>
<option value="ASPMAIL">ASPMAIL</option>
<option value="QMAIL">ASPQMAIL</option>
<option value="CDOSYS">CDO.Message</option>
</select>
<input value=submit type=submit>
</form>
<%
u_email = Request.Form("email")
if u_email <>"" then
u_method=Request.form("mailobject")
s_servername = Request.ServerVariables("SERVER_NAME")
s_from = "mailtest@" & s_servername
if u_method = "ASPMAIL" or u_method = "QMAIL" then
set Mailer = Server.CreateObject("SMTPsvg.Mailer")
if u_method = "QMAIL" then
'This is pretty much setting qmail right here
'if its not set then pretty much its aspmail sending it
Mailer.QMessage = "true"
Mailer.Subject = "Testing ASPQmail"
else
Mailer.Subject = "Testing ASP Mail"
end if 'ASPQMAIL
Mailer.FromName = "Test"
Mailer.FromAddress= s_from
Mailer.RemoteHost = "localhost"
Mailer.AddRecipient "Test",u_email
Mailer.BodyText = "This is a Test"
Mailer.SMTPLog = server.mappath("./smtp.log")
if Mailer.SendMail then
Response.write "To: " & u_email
Response.write "From: " & s_from
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if 'sendmail success
elseif u_method = "CDONTS" then
Dim MyBody
Dim MyCDONTSMail
Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
MyCDONTSMail.From= s_from
MyCDONTSMail.To= u_email
MyCDONTSMail.Subject="This is a Test"
MyBody = "testing email" & vbCrLf
MyBody = MyBody & "CDONTS seems fine" & vbCrLf
MyCDONTSMail.Body= MyBody
MyCDONTSMail.Send
set MyCDONTSMail=nothing
Response.write "To: " & u_email
Response.write "From: " & s_from
elseif u_method ="CDOSYS" then
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "localhost"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = s_from
.To = u_email
.Subject = "Testing email"
.TEXTBody = "CDOSYS aka CDO.Message worked"
.send
End With
Response.write "To: " & u_email
Response.write "From: " & s_from
Set cdoMessage = Nothing
Set cdoConfig = Nothing
end if
end if
%>
CDO MAIL SEPARATE FORMAT
<%
Dim objCDOMail
Set objCDOMail = Server.CreateObject("CDONTS.NewMail") ' Create instance of NewMail object.
Dim strBody
strBody = "Opening line of email:" & vbCrLf & vbCrLf
strBody = strBody & "Name: " & Request.Form("name") & vbCrLf
strBody = strBody & "Address: " & Request.Form("address") & vbCrLf
strBody = strBody & "City: " & Request.Form("city") & vbCrLf
strBody = strBody & "State: " & Request.Form("state") & vbCrLf
strBody = strBody & "Zip: " & Request.Form("zip2") & vbCrLf
strBody = strBody & "Day-Phone: " & Request.Form("Day_Phone") & vbCrLf
strBody = strBody & "Biz-Phone: " & Request.Form("Biz_Phone") & vbCrLf
strBody = strBody & "Email: " & Request.Form("email") & vbCrLf
strBody = strBody & "Birth-Day: " & Request.Form("birth_day") & vbCrLf
strBody = strBody & "Educational History: " & Request.Form("Educational_History") & vbCrLf
strBody = strBody & "Interested in Attending: " & Request.Form("interested_in_attending") & vbCrLf
strBody = strBody & "Course of Study: " & Request.Form("Course_of_Study") & vbCrLf
strBody = strBody & "Start-Date: " & Request.Form("Start_Date") & vbCrLf
strBody = strBody & "Best-Time: " & Request.Form("Best_Time") & vbCrLf
strBody = strBody & "Comments: " & Request.Form("q") & vbCrLf
strBody = strBody & "-----------------------------------------------"
objCDOMail.From = "CompanyName <[email protected]>"
objCDOMail.To = "[email protected]"
objCDOMail.Subject = "Subject"
objCDOMail.Body = strBody
objCDOMail.Send
%>