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
Related
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
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.
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");
My ASP, classic ASP application is giving me a sever error on a Windows 2008 Server. It works fine on Windows 2003 server. The error is a 500 internal server error. Does CDO not work on Windows 2008?
EDIT
THe error is: The transport failed to connect to the server.
Here is my mail function:
function SendMail(mailFrom, mailTo, mailSubject, mailBody, bHtml)
Const cdoSendUsingMethod = _
"http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = _
"http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = _
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = _
"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = _
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = _
"http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = _
"http://schemas.microsoft.com/cdo/configuration/sendpassword"
Const smtpServer = "localhost"
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = smtpServer
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = mailTo
.From = mailFrom
.Subject = mailSubject
if bHtml then
.HtmlBody = mailBody
else
.TextBody = mailBody
end if
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
end function
It appears that the CDO/MAPI libraries aren't installed by default in Windows 2008:
You can download them from Microsoft.
Referenced from this blogpost:
If you want to write client
applications to run on computers that
use MAPI or CDO (for example, web
servers) and you don't want to install
(or can't install) either the Outlook
client or the Exchange management
tools, then you need to install the
MAPI/CDO libraries.
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