Is CDO Email the best way to send email using classic asp? - email

I am using asp to create a webpage that is supposed to send email to several clients. It was suggested that I use CDO email functionality. Is this the best solution for a classic asp webpage? Or would it be better to add asp.net and ajax for handling email this type of thing.

CDO would be the obvious route. In some versions of the .Net Framework ASP.Net would just be using a wrapper around CDO anyway.
I have no clue where Ajax fits into this topic.
Crude and rude (better to reference the library in global.asa to get type info and avoid the long Field ID strings and magic numbers) example copy/pasted and not verified by me:
<%
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "<enter_mail.server_here>"
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "from#me.com"
.To = "to#me.com"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO.message"
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>

Are you wanting to add Ajax to ClassicASP? I would say you are asking for trouble. If at all possible, I would encourage the customer to move to .net technology. They will be thankful in the long run.
As far as CDO objects, try out this link How do I send e-mail with CDO?

It works this way on ASP Classic using CDO on GoDaddy hosting :
<%
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="relay-hosting.secureserver.net"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
'ObjSendMail.AddAttachment mPath, "Logo.gif"
'ObjSendMail.AddAttachment ArrwPath, "red_arrw.gif"
ObjSendMail.Subject = strSub
ObjSendMail.To = strTo
ObjSendMail.From = strFrom
ObjSendMail.Bcc = strBcc
ObjSendMail.Cc = strCc
ObjSendMail.HTMLBody = strMsg
ObjSendMail.Send
Set ObjSendMail = Nothing
%>

Related

Send multiple messages in ASP

After an internal form is submitted, I want an email to go to the form-filler with specific information and then a new email sent to the customer with different information. As of right now, with what I have, I can make the first email go, but how do I reset the mailer and do it all over again on the same page?
I can make it work if I double-up the code below, but the AddAddress list doesn't reset. The recipients added in the first iteration will still be on the AddAddress list for the second iteration.
This is what I have so far:
message= "<html><body><table><tr><td>Blah blah blah</td></tr>"
message=message & "<tr><td>Something something.</td></tr>"
message=message & "</table></body></html>"
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "domain-com.mail.protection.outlook.com"
Mail.From = "website#domain.com"
Mail.FromName = "person#domain.com"
Mail.AddAddress "me#domain.com"
Mail.Subject = "Gast Repair. Enter P21 order for: " & request.form("CompanyName")
Mail.Body = message
Mail.IsHTML = True
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
'response.write "<P>" & strErr & "</P>"
else
bSuccess = True
'response.redirect sendto
End If
Thanks for the help!
Why use Persits?
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strOutgoingMailServer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = strSmtp-auth
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strSmtp-pass
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = "Somebody <somebody#example.com>"
ObjSendMail.Subject = strSubject
ObjSendMail.From = strFromName & " <no-reply#example.com>"
ObjSendMail.ReplyTo = strFromName & " <" & strFromEmail & ">"
ObjSendMail.BodyPart.Charset = "UTF-8"
ObjSendMail.TextBody = strEmailBody
ObjSendMail.TextBodyPart.Charset = "UTF-8"
On Error Resume Next
ObjSendMail.Send
Set ObjSendMail = Nothing
Then write a new strEmailBody (message) and run this code again for the new recipient.
If you have problems sending via SMTP server on Windows server, try installing the free hmailServer software.
The official documentation for the Persits.MailSender COM component provides a few methods;
Reset()
Clears all address, attachment and custom header lists so that a new message can be sent.
ResetAddress()
Clears all address lists so that a new message can be sent. Does not clear attachments, embedded images, custom headers or properties.
There is also
ResetAll()
Same as Reset plus resets all properties to their respective default values.
Note: This will completely reset the Mail object back to its default values.
I would give these a try.

Sending email with Classic ASP through Godaddy

I'm trying to send email using Classic ASP from my website at Godaddy. Unfortunately, the cod I have from 10-15 years ago doesn't work (imagine that! lol). Here's the code. Can someone tell me what has changed since then? desperately await your reply. Thank you!
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = false
.Item(cdoSendUserName) = "email#mywebsite.com"
.Item(cdoSendPassword) = "MyPassword"
.Item(cdoURLProxyServer) = "server:25"
'.Item(cdoSendUsingMethod) = cdoSendUsingPickup
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "relay-hosting.secureserver.net"
.Item(cdoURLGetLatestVersion) = True
.Update
End With
'Create mail object
Set cdoMessage = CreateObject("CDO.Message")
'Apply the settings to the message object then send the email
With cdoMessage
Set .Configuration = cdoConfig
.From = "Support (email#mywebsite)"
.To = "The User (user#email.com)"
.BCC = ""
.Subject = "This is a test email."
.TextBody = "This is a test email. If it were a real email there would be some blah blah blah here! This concludes the test of the Godaddy email message."
.Send
End With
'Cleanup mail objects
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Ok folks. This is for the people that need a guiding hand from time to time. However, make sure you enter the right username and password. When hosting on Godaddy you could have up to three different usernames and passwords. You have your Godaddy account username and password (that's not it!), you have a username and password for Plesk (that's not it either!). Then you have a username and password for your primary website (that's the one you want!). Even though you might have several different websites under your hosting, only one will be the primary. Mine was for the email and password that are associated with that prime website. Once you get this code posted you should be good to go. However, you might have to wait a while in order for it to start working. For me it took about 8 hours for the DNS to catch hold of what I was doing and start sending my emails through. Once it did though, now it works great! Enjoy!
Dim objNewMail
'Your email information
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "your-email#this-website.com"
objNewMail.Cc = "your-email#this-website.com"
objNewMail.To = "send-to#their-email.com"
objNewMail.Subject = "This is a test email"
objNewMail.TextBody = "this is a test email"
' GoDaddy SMTP Settings
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="relay-hosting.secureserver.net"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUserName") = "your-primary-website-username"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendPassword") = "your-primary-website-password"
objNewMail.Configuration.Fields.Update
objNewMail.Send
'After the Send method, NewMail Object become Invalid
Set objNewMail = Nothing

Classic ASP Mail - Error send to user and admin

I am sending a mail using CDO.Message. When the user submits a form, the form details to be sent to the Web Site Owner and a Acknowledgement mail to the user. The later is not working for me. I have repeated the same code twice by changing the configuration names, I simply get "Internal Server Error"
My Code (mail to the Web Site Owner)
<%
name = Request.Form ("name")
email = Request.Form ("email")
phone = Request.Form ("phone")
message = Request.Form ("message")
Dim iMsg, iConf, Flds, vSub
Response.CodePage = 65001
Response.CharSet = "utf-8"
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'sending email with Google Apps Premium SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "smtpserver") = "localhost"
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "sendusername") = "info#priceakagri.ru"
Flds.Item(schema & "sendpassword") = "******"
Flds.Update
With iMsg
Set .Configuration = iConf
.BodyPart.Charset = "utf-8"
.To = "info#akagri.ru"
.From = "info#priceakagri.ru"
.Subject="Message from Priceakagri.ru contact page"
.HTMLBody="Здравствуйте! <br><br>You have received an Enquiry from <font color='#337AB7'><b>" & Trim(Request("name")) & "</b></font>.<br><br><br><table><tr><td width='30%' colspan='2' bgcolor='#337AB7'>Message Details</td></tr><tr><td>Name</td><td>" & Trim(Request("name")) & "</td></tr><tr><td>Email</td><td>" & Trim(Request("email")) & "</td></tr><tr><td>Phone</td><td>" & Trim(Request("phone")) & "</td></tr><tr><td>Message</td><td>" & Trim(Request("message")) & "</td></tr></table>"
Set .Configuration = iConf
.Send
End With
set iMsg = nothing
set iConf = nothing
set Flds = nothing
%>
The above code works perfectly for me. If I replicate the same and send user a mail on acknowledgement, I get error. I used the users email as .To and From as - info#priceakagri.ru
I have done this in my earlier sites, where I include a .txt file for the later and still is working for me.
Need help.
Regards,
Badri

Sending mail using classic ASP?

I am trying to send mail using classic ASP, but my page contain some error that's why when
upload the page it shows the error that :
500 Internal Server Error
This is the code i am using;
<%
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError
smtpserver = "smtp.gmail.com"
youremail = "xxxxx.yyyyyy#gmail.com"
yourpassword = "password"
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 'Use SSL for the connection
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "aaaaa.bbbbbb#gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = "aaaaa.bbbbbb#gmail.com"
ObjSendMail.CC = "cccccc.dddddd#sunarctechnologies.com"
ObjSendMail.Subject = "Subject"
ObjSendMail.From = "xxxxx.yyyyyy#gmail.com"
ObjSendMail.HTMLBody = "<p>hello</p>"
ObjSendMail.Send
Set ObjSendMail = Nothing
%>
I don't have any idea of classic asp this is just copy paste code from some other source.
Your code looks correct but I'd check wheter gmail only accepts SSL connections on port 465. I believe port 567 is for TLS connections. Alternatively just try port 25.
This question is similar to yours.
You also really need to be able to see the detailed error messages your application is reporting.
Assuming you have access to IIS, the first thing I recommend is to activate server side debugging and send errors to browser on in IIS. An error 500 can mean anything form a missing end if to the object not being found. Having a proper error message to work with will help narrow down the source of the problem.

Classic ASP using Email and Local Server

Basically, I have created a form with a To, From, Subject and Textbody, all named appropriately. What I need to know is what code I need to use Classic ASP to link to a local port, to test my code and send an email,
I have IIS installed at the moment and some other little programs, but I can't get my head around it.
Sending an email in vbscript is usually done in via CDO - example using gmails SMTP server (note the use of configuration/smtpserverport and configuration/smtpusessl)
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="info#thedomain.com" '#### Gmail Username (usually full email address)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="password" '#### Gmail Password
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = ""
ObjSendMail.Subject = ""
ObjSendMail.From = ""
ObjSendMail.TextBody = "Hello World"
ObjSendMail.Send
Set ObjSendMail = Nothing