Difference between revisions of "ASP Mail"
From KOP KB
(→Fake Email) |
|||
(17 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
== CDO == | == CDO == | ||
− | <syntaxhighlight lang="asp"> | + | <syntaxhighlight lang="asp" enclose="div"> |
elseif u_method ="CDOSYS" then | elseif u_method ="CDOSYS" then | ||
sch = "http://schemas.microsoft.com/cdo/configuration/" | sch = "http://schemas.microsoft.com/cdo/configuration/" | ||
Line 33: | Line 33: | ||
== CDONTS == | == CDONTS == | ||
− | <syntaxhighlight lang="asp"> | + | <syntaxhighlight lang="asp" enclose="div"> |
elseif u_method = "CDONTS" then | elseif u_method = "CDONTS" then | ||
Line 50: | Line 50: | ||
Response.write "From: " & s_from | Response.write "From: " & s_from | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
== ASPMAIL AND QMAIL == | == ASPMAIL AND QMAIL == | ||
− | <syntaxhighlight lang="asp"> | + | <syntaxhighlight lang="asp" enclose="div"> |
if u_method = "ASPMAIL" or u_method = "QMAIL" then | if u_method = "ASPMAIL" or u_method = "QMAIL" then | ||
Line 77: | Line 78: | ||
end if 'sendmail success | end if 'sendmail success | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
== Full Script == | == Full Script == | ||
− | <syntaxhighlight lang="asp"> | + | [[#top|Top of Page]]<br /> |
+ | <syntaxhighlight lang="asp" enclose="div"> | ||
<form action=mailtest.asp method=post> | <form action=mailtest.asp method=post> | ||
<div>Enter the email you would like to send to: <input type=text name=email> using the mailer: | <div>Enter the email you would like to send to: <input type=text name=email> using the mailer: | ||
Line 169: | 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> | ||
+ | == Basic Format == | ||
+ | <syntaxhighlight lang="asp" enclose="div"> | ||
+ | <% | ||
+ | ' change to address of your own SMTP server | ||
+ | strHost = "smtp.servername.com" | ||
+ | |||
+ | |||
+ | If Request("Send") <> "" Then | ||
+ | Set Mail = Server.CreateObject("Persits.MailSender") | ||
+ | ' enter valid SMTP host | ||
+ | Mail.Host = strHost | ||
+ | |||
+ | Mail.From = Request("Form_Email") ' From address preferably the name from the email thats put into the form | ||
+ | Mail.FromName = Request("Form_Email") ' optional | ||
+ | Mail.AddAddress "[email protected]" | ||
+ | |||
+ | ' message subject | ||
+ | Mail.Subject = "Subject" | ||
+ | ' message body | ||
+ | |||
+ | Mail.Body = "First Name: " & Request("Contact_FirstName") & vbCrLf & "Last Name: " & Request("Contact_LastName") & vbCrLf & "Street Address: " & Request("Contact_StreetAddress") & vbCrLf & "Address 2: " & Request("Contact_Address2") & vbCrLf & "City: " & Request("Contact_City") & vbCrLf & "State: " & Request("Contact_State") & vbCrLf & "ZipCode: " & Request("Contact_ZipCode") & vbCrLf & "Country: " & Request("Contact_Country") & vbCrLf & "Work Phone: " & Request("Contact_WorkPhone") & vbCrLf & "Home Phone: " & Request("Contact_HomePhone") & vbCrLf & "Email: " & Request("Contact_Email") & vbCrLf & "Number of Adults: " & Request("Adults") & vbCrLf & "Number of Children: " & Request("Children") & vbCrLf & "Arrival Date: " & Request("Arrival") & vbCrLf & "Departure Date: " & Request("Departure") & vbCrLf & "Cabin Choice: " & Request("CabinChoice") & vbCrLf & "Comments: " & Request("Comments") | ||
+ | |||
+ | strErr = "" | ||
+ | bSuccess = False | ||
+ | On Error Resume Next ' catch errors | ||
+ | Mail.Send ' send message | ||
+ | If Err <> 0 Then ' error occurred | ||
+ | strErr = Err.Description | ||
+ | else | ||
+ | bSuccess = True | ||
+ | End If | ||
+ | End If | ||
+ | |||
+ | |||
+ | %> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Server Settings == | ||
+ | <syntaxhighlight lang="asp" enclose="div"> | ||
+ | myMail.Configuration.Fields.Item _ | ||
+ | ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 | ||
+ | 'Name or IP of remote SMTP server | ||
+ | myMail.Configuration.Fields.Item _ | ||
+ | ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com" | ||
+ | 'Server port | ||
+ | myMail.Configuration.Fields.Item _ | ||
+ | ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 | ||
+ | myMail.Configuration.Fields.Update | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | == Fake Email == | ||
+ | <syntaxhighlight lang="asp" enclose="div"> | ||
+ | <% | ||
+ | Set myMail=CreateObject("CDO.message") | ||
+ | |||
+ | stremail = Request.Form("email") | ||
+ | |||
+ | if(stremail <> "") Then | ||
+ | myMail.From= stremail | ||
+ | else | ||
+ | myMail.From= "[email protected]" | ||
+ | end if | ||
+ | |||
+ | |||
+ | myMail.To="[email protected]" | ||
+ | myMail.Subject="Inquiry Request" | ||
+ | myMail.TextBody="Name: " & Request.Form("name") & vbCrLf & "Email: " & Request.Form("email") & vbCrLf & "Phone Number: " & Request.Form("phone") & vbCrLf & "Address: " & Request.Form("address") & vbCrLf & "Case Description: " & Request.Form("case_description") & vbCrLf & "Additional Comments: " & Request.Form("comments") & vbCrLf & "-----------------------------------------------" | ||
+ | |||
+ | myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 | ||
+ | 'Name or IP of remote SMTP server | ||
+ | myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.domain.com" | ||
+ | 'Server port | ||
+ | myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 | ||
+ | myMail.Configuration.Fields.Update | ||
+ | |||
+ | |||
+ | |||
+ | myMail.Send | ||
+ | set objCDOMail=nothing | ||
%> | %> | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 19:17, 16 March 2016
This is more of a testing script for trying out different types of email there are you can try through asp.
Contents
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
%>
Basic Format
<%
' change to address of your own SMTP server
strHost = "smtp.servername.com"
If Request("Send") <> "" Then
Set Mail = Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = strHost
Mail.From = Request("Form_Email") ' From address preferably the name from the email thats put into the form
Mail.FromName = Request("Form_Email") ' optional
Mail.AddAddress "[email protected]"
' message subject
Mail.Subject = "Subject"
' message body
Mail.Body = "First Name: " & Request("Contact_FirstName") & vbCrLf & "Last Name: " & Request("Contact_LastName") & vbCrLf & "Street Address: " & Request("Contact_StreetAddress") & vbCrLf & "Address 2: " & Request("Contact_Address2") & vbCrLf & "City: " & Request("Contact_City") & vbCrLf & "State: " & Request("Contact_State") & vbCrLf & "ZipCode: " & Request("Contact_ZipCode") & vbCrLf & "Country: " & Request("Contact_Country") & vbCrLf & "Work Phone: " & Request("Contact_WorkPhone") & vbCrLf & "Home Phone: " & Request("Contact_HomePhone") & vbCrLf & "Email: " & Request("Contact_Email") & vbCrLf & "Number of Adults: " & Request("Adults") & vbCrLf & "Number of Children: " & Request("Children") & vbCrLf & "Arrival Date: " & Request("Arrival") & vbCrLf & "Departure Date: " & Request("Departure") & vbCrLf & "Cabin Choice: " & Request("CabinChoice") & vbCrLf & "Comments: " & Request("Comments")
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
else
bSuccess = True
End If
End If
%>
Server Settings
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
Fake Email
<%
Set myMail=CreateObject("CDO.message")
stremail = Request.Form("email")
if(stremail <> "") Then
myMail.From= stremail
else
myMail.From= "[email protected]"
end if
myMail.To="[email protected]"
myMail.Subject="Inquiry Request"
myMail.TextBody="Name: " & Request.Form("name") & vbCrLf & "Email: " & Request.Form("email") & vbCrLf & "Phone Number: " & Request.Form("phone") & vbCrLf & "Address: " & Request.Form("address") & vbCrLf & "Case Description: " & Request.Form("case_description") & vbCrLf & "Additional Comments: " & Request.Form("comments") & vbCrLf & "-----------------------------------------------"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.domain.com"
'Server port
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set objCDOMail=nothing
%>