cdonts and relay server? - asp-classic

I use CDONTS when I need to send up send email form on websites. Recently changed my hosting company to godaddy. I realized my send email form gives "permission denied" error. I called GoDaddy support. They told me I should use relay server "relay-hosting.secureserver.net" in my codes. I thought relay server used only with CDO.
How can I include it to my codes?
My codes
Set objEmail = Server.CreateObject("CDONTS.NewMail")
objEmail.To = MailTo
objEmail.Cc = MailCc
objEmail.From = MailFrom
objEmail.Subject = MailSubject
objEmail.Body = MailBody
objEmail.Send
Set objEmail = nothing

A web search for "cdonts relay" yielded this example which relates directly to your issue with GoDaddy.com - Based on everything I've read, this only works with CDO.Message instead of CDONTS.NewMail.
UPDATE: Here's the modified code
Set objMail = Server.CreateObject("CDO.Message")
objMail.From = MailFrom
objMail.To= MailTo
objMail.Subject = MailSubject
objMail.TextBody = MailBody
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update
objMail.Send
set ojbMail = nothing

Related

Send automatic email SSL Implicit ASP.NET VB

this code is inside a "for next" loop and sends an email through an implicit SSL server.
Last week I had to change the smtp server and now this new smtp server has a block that does not allow simultaneous connection to more than 5 users.
If the for loop sends more than 5 emails I get the error "Too many simultaneous connections".
I think this occurs because the emails are sent in a NON ASYNCHRONOUS way and consequently the sending of the email takes too long.
I would like to ask if it is possible to use CDO.message ASYNCHRONOUSLY or if you can recommend another code that sends emails synchronously using an implicit SSL server.
Thank you
Dim objEmail = CreateObject("CDO.Message")
Dim objConf = objEmail.Configuration
Dim objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
.Update()
End With
objEmail.To = email_cli
objEmail.From = ConfigurationManager.AppSettings("p_email")
objEmail.Subject = mailOggetto
objEmail.HTMLBody = testo_email
Try
objEmail.Send()
Catch ex As Exception
FailureText.Text = ex.Message
Exit Sub
Finally
objEmail = Nothing
objConf = Nothing
objFlds = Nothing
End Try

How to prevent outlook.office.com from displaying message source in emails

Our club directors are using online.outlook.com as a webmail solution for messaging, and I have noticed something peculiar in that while messages sent to the directors from a mail client like Thunderbird look ok, any emails sent from our online webform look a mess.
For example...
Contact = 192.168.0.2 via /contact.asp?
ID=7&Subject=Text+format&Name=John&Email=john%40example.com&Message=Click+inside+calendar+to+add+event%2C+move+or+resize+existing+events%2C+select+multiple+days%2C+etc.&g-recaptcha-response=03AGdBq26BbA8M9TkyW521mNLZ6nksqV4EdzajclTJ653GsN4E3opCUKEdrt5hA1orva_V3OF7TghktsatMauhu1Oue6TzMF2xO1wPssI7PCOiwMKcdVGWEprbRkaBxKhyJWo52vFNiuN3cO8xobvydyNcbKyYqPNWn0dZVwhN2Tav4WRQWOp5x1-0lANfpVBtVz8RaxoeAMii5e97tgCbGb06y0VjusA6zYappXDl__E95Zm5Lxm7TakVGhWx-SzRpFsmJJB3aCP1TvsEJIDMn3NN31OZA2SpsvblGywTdAUYQoy7VaWghjgcOoOdCZ2y-oE06l2p5OZ5q1Et_w4SClcrouAjL4rge-i8EIucpYJHKJZtPPoDTT9HPlc4h0T0Hab8frxxeB280O22kPicnYo7lAkU_3TCoj39eYEfyv1s40F5m9opfVF5p36mMRRVcpasp6EXjlwVf8FM6fAgqaMYGd6S6_u1vw&Submit=Submit
-------------------------------------------------------------
Name: John
Email: john#example.com
Subject: Text format
-------------------------------------------------------------
Dear John
Click inside calendar to add event, move or resize existing events, select multiple days, etc.
Everything above "Name: John" should not be shown and is not shown when the email is sent from Thunderbird.
The code that I used on the mail page looks like...
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... /sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... smtpserver") = strMailServer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... thenticate") = strSmtpAuthenticate
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... ndusername") = strSmptAuthUser
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... ndpassword") = strSmptAuthPass
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... serverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... iontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = strName & " <" & strEmail & ">"
ObjSendMail.Subject = strSubject
ObjSendMail.From = strFromName & " <" & strFromEmail & ">"
ObjSendMail.ReplyTo = strSender & " <" & strSenderEmail & ">"
ObjSendMail.BodyPart.Charset = "UTF-8"
ObjSendMail.TextBody = strEmailBody
ObjSendMail.TextBodyPart.Charset = "UTF-8"
On Error Resume Next
ObjSendMail.Send
Set ObjSendMail = Nothing
Charset for the page is set to UTF-8.
Anyone seen this before and know how to prevent it?
I had a similar problem and spent days trying to solve it. In the end it was quite simple to fix but difficult to understand how it could be so. But I finally got to send emails that didn't include header data in the email body.
I found that all my pages were using the same include.asp that contained a collection of functions. I solved the problem when I disabled any that were using server variables such as...
strCheckIPnumber = Request.ServerVariables("REMOTE_ADDR")
I didn't want to lose those server variables, so I made their collection conditional so that the webforms for email could exclude them.

Unable to send email with IIS7

I'm migrating a website from IIS6 to IIS7. I have everything working but the site will not send emails.
I have confirmed that the server is handling emails correctly, because when I drop a text document into the pickup folder it is delivered, but when I try to send a message via code I either get an error or just nothing.
The SMTP virtual server is setup with standard settings.
The website in question is using 4.0 Framework, Integrated Application pool, I've tried both the ApplicationPoolIdentity, and the NetworkService with no effect. For the site's SMTP module I've tried an SMTP server of 127.0.0.1, localhost and the server's domain name, all on port 25.
For testing I've been using VBS and classic asp to send an email as well as asp.net.
I've been trying very basic scripts copied off the internet where all the comments say that it works. For example
vb.net. This code shows no error, but no message is sent and I've found nothing in the event viewer
Public Shared errorEmailTo As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailTo")
Public Shared errorEmailFrom As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim email As String = "This is a test email."
show.Text = "To: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailTo") + "<br/>"
show.Text += "From: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom") + "<br/>"
Try
Helper.SendError(email)
show.Text += "No Error"
Catch ex As Exception
show.Text += "Error: " + ex.Message
End Try
End Sub
Public Shared Sub SendError(ByVal strBody As String)
Dim Email As New System.Net.Mail.MailMessage(errorEmailFrom, errorEmailTo)
Email.Subject = "Error Message"
Email.Body = strBody
Dim mailClient As New System.Net.Mail.SmtpClient()
mailClient.UseDefaultCredentials = True
mailClient.EnableSsl = False
Try
mailClient.Send(Email)
Catch ex As Exception
End Try
End Sub
VBS. This code returns the error "The transport failed to connect to the server." For which I've not found anything other than a new nearly identical code block
strSMTPFrom = "donotreply#here.com"
strSMTPTo = "me#here.com"
strSMTPRelay = "localhost"
strTextBody = "Body of your email"
strSubject = "Subject line"
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.Send
Classic ASP gives the same error message.
<%
Dim sch, cdoConfig, cdoMessage
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "localhost"
.Item(sch & "smtpserverport") = 25
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "donotreply#here.com"
.To = "me#here.com"
.Subject = "Email test"
.TextBody = "This is the test body of the email"
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>
I've found example after example that give these code blocks as working examples, what am I doing wrong?
Brought in a fresh pair of eyes, and we found the answer.
The virtual SMTP server was listening on port 465(SSL), not 25. So with that corrected, classic ASP and VBS worked, but not VB.Net. We created a new Virtual SMTP server, listening on port 587. And as long as VB.Net had SSL disabled it would work. It appears that the new server didn't receive the SSL certificate during migration.

ASP WebMail: Set up SMTP authentication?

I'm developing web pages using Razor C# language in WebMatrix. I have a hosted website, I'm trying to incorporate an email system into it.
As per this article on WebMail I have set up the WebMail settings in my _AppStart.cshtml page. I've got my settings from my service provider. He's provided me a sample code using CDO object:
dim config, sch
set config = CreateObject("CDO.Configuration")
sch = "http://schemas.microsoft.com/cdo/configuration/"
with config.Fields
.item(sch & "sendusing") = 2 ' cdoSendUsingPort
.item(sch & "smtpserver") = "myserver"
.item(sch & "smtpserverport") = 25
.item(sch & "smtpusessl") = False
.item(sch & "smtpconnectiontimeout") = 60
.item(sch & "smtpauthenticate") = 1 'basic auth
.item(sch & "sendusername") = "myemail#email.com"
.item(sch & "sendpassword") = "password"
.update
end with
Set myMail=CreateObject("CDO.Message")
With myMail
.Configuration = config
.Subject = Request.Form("txtSubject")
.From = Request.Form("txtFrom")
.To = Request.Form("txtTo")
.TextBody = Request.Form("txtMessage")
Call .Send()
End With
As you can see the above code is made in CDO. I'm trying to use the WebMail in Razor. The only point where I'm stuck is that my email server is not SSL but requires basic auth. I can't find any authentication setting in WebMail. How do I set the SMTP authentication in WebMail? This is my current code:
WebMail.SmtpServer = "myserver";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "myemail#email.com";
WebMail.Password = "password";
WebMail.From = "Support <myemail#email.com>";
Thanks in advance!
Basic authentication with mail servers usually consists of providing a user name and password. You set those using the WebMail.UserName and WebMail.Password properties.
By the way, your provider has given you sample code for sending mail using CDO in classic ASP. It is of no use to you.
Here's a basic example in c#. The Smtp class takes username password.
MailMessage mail = new MailMessage("emailfrom","emailto");
mail.From = new MailAddress("emailfrom");
mail.Subject = txtsbjct.Text;
string Body = txtmsg.Text;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "localhost";
smtp.Credentials = new System.Net.NetworkCredential
("youremail", "yourpassword");

Sending email through CDOSYS but written in C#

I am sick and tired of my hosting company. I think you can help me here.
I have simple need that I have my complete website written in Classic ASP. Now I want to have a page which sends email using CDOSYS. I wanted to have that script in ASP from my hosting company that what setting should i have. They always send me code in C#.
here is they send always:
CDOSYS is part of the System.Web.Mail namespace and is installed by default on Windows 2000 and Windows XP platforms. It replaces CDONTS for sending SMTP email messages and can be used with our IIS 6 and IIS 7 Windows hosting accounts. The following code sample demonstrates how to create, format, and send email.
private void SendEmail()
{
const string SERVER = "relay-hosting.secureserver.net";
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.From = "emailaddress#domainname";
oMail.To = "emailaddress#domainname";
oMail.Subject = "Test email subject";
oMail.BodyFormat = MailFormat.Html; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = "Sent at: " + DateTime.Now;
SmtpMail.SmtpServer = SERVER;
SmtpMail.Send(oMail);
oMail = null; // free up resources
}
Here is my ASP which I written to use same thing but doesn't work:
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update
With objCDOSYSMail
.To = strEmail
.BCc = "a#gmail.com"
.Cc = "b#gmail.com"
.From = "sales#b.com"
.Subject = "Thank you!"
.HTMLBody = "Hello<br></br><h3>Thank you for your enquiry. <br/>"
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
I don't know how to use their code.... please help
You can use the following code in a classic ASP page to send email with CDOSYS:
Set objMail = Server.CreateObject("CDO.Message")
Set objConf = Server.CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.your-site-url.com" 'your smtp server domain or IP address goes here
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email
'uncomment next three lines if you need to use SMTP Authorization
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
objFlds.Update
objMail.Configuration = objConf
objMail.FromName = "Your Name"
objMail.From = "your#address.com"
objMail.To = "destination#address.com"
objMail.Subject = "Email Subject Text"
objMail.TextBody = "The message of the email..."
objMail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objMail = Nothing

Resources