CDOSYS error '80040213' - failed to connect to server - asp-classic

I have a Windows Server 2003 R2 running IIS and a website using classic ASP.
Trying to get it to use CDOSYS to email using our own (externally) hosted office365 exchange server.
I get the following error
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
Which usually means one of 3 problems:
1. Incorrect SMTP server / port
2. Incorrect login/password
3. FROM address not valid according to SMTP server (wrong domain)
The SMTP server and port are correct according to supplier.
The login/password is correct as I can log into the mail account using those details
The FROM address is correct as that is the account I am using to log in.
I can telnet to the exchange server from the web server on that address and port, so a connection can be made from the server at least.
So at the moment I'm at a loss as to what the problem might be.
Does anyone have any pointers as to anything else I need to look at?
This is the config the website is using
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

Did you setup an SMTP relay in Office 365?
From the Office 365 Admin go to:
Admin > Exchange
Mail Flow > Connectors
Click add new SMTP relay connector
Select from "your organization's email server" to "office 365"
Give the connector a name and description
Select verify by IP address and add your web server IP
Save

Try Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
With Office 365, cdo seems to prefer port 25, even when using authentication.
Here's a tried and tested configuration if it helps
Set iConfg = Server.CreateObject("CDO.Configuration")
Set Flds = iConfg.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Update
End With
objMail.Configuration = iConfg

Try
.Item("http://schemas.microsoft.com/cdo/configuration/smtpsendtls") = 1
instead of
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

Well I eventually got this solved.
I needed to use a different method of connecting to the office365 server.
So all is working as it should now.

Related

Cannot connect to database (free host somee.com)

I recently created a .aspx-website for a school project and it is hosted for free on www.somee.com. Also included in the host's free package is a database (SQLServer).
I don't have SQLServer at home but i need to use the database so I ran a query to create all tables needed. So far everything worked, the database exists (I see this in somee.com's member area) and my website can be visited.
However, I want to Insert/Updata/Delete data from my code behind. I got the following connection-string from my host:
workstation id=sskDatabase.mssql.somee.com;packet size=4096;user id=****;pwd=****;data source=sskDatabase.mssql.somee.com;persist security info=False;initial catalog=sskDatabase
Unfortunately it's not working.
In my web.config:
and my code behind:
connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
string commandString = String.Format("INSERT INTO Mitglied (Position_Id, Username, Passwort, EMail, Beitrittsdatum, aktiv) VALUES ({0},'{1}','{2}','{3}','{4}',{5})", 0, mitglied.Username, mitglied.Password, mitglied.EMail, DateTime.Now, 1);
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandType = System.Data.CommandType.Text;
sqlCommand.CommandText = commandString;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
sqlCommand.Connection = sqlConnection;
sqlCommand.Connection.Open();
sqlCommand.ExecuteNonQuery();
sqlCommand.Connection.Close();
}
It crashes at sqlCommand.Connection.Open(); with the following error message:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=119; handshake=14883;
Any ideas why I can't connect to my database?
Contact their support? Normally you should not be able to connect - the database should be hired behind a firewall, likely they changed the default port number at least.
This here is not a replacement for your host's support, you know.
Are you trying it from your school labs? I had the same problem with the same host. In my project it was the school firewall that prevent me from connecting to the database. It's a long shot you can try to connect from your own network (at home or by using your phone as access point) and see if it still happening.
First, you should check if the database server is available, easily you can use a ping command to your ip server adresse.
If the databse server is available you could check if the port of the instance is available, the default is 1433.
To do this you can use telnet command like in this example :
telnet XXX.XX.XX.XX 1433
A important thing that you have to know is that a SQL Server service browser is looking for a client call in the server side, it's this service which receives the call and able the communication. You have to make sure that this service is working too.

Sending mail using SMTP settings?

I have a code for sending mail using SMTP settings in asp.net. That code is working well on live but when i am testing the same on localhost. It shows the error:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for abc.xyz.com
I know this is some configuration related error, but i don't know exactly what i need to change to test the same on localhost. I have defined these attributes for SMTP:
smtp.Host = "abc.server.net";
smtp.Port = 123;
smtp.EnableSsl = false;
fromEmail="any email";
password="password"
Any help would be appreciated.
You have to configure relay restrictions in the IIS admin. see this article
try this
Open IIS Manager using Control Panel --> Administrative Tools.
Open SMTP Virtual Server properties.
On General tab, Set IP address of the Web server instead of "All Unassigned".
In Access tab, click on Relay button, this will open Relay Restrictions dialog.
In relay computers list, add the loopback IP address i.e 127.0.0.1 and IP address of the Web server, so that they can pass/relay emails through the SMTP server.
source : SO

mailsending issues with new mailserver

i am using for send mail my smtp server is "xxx.xx.x", its working fine. But now i am changing the mail server for emails. i am using new mail smtp server ip address is "xxxxxxx.xxx.xxx", in this case get the error like "The server rejected one or more recipient addresses. The server response was: 554 5.7.1 : Client host "
i am using the bellow code
Dim eMail As MailMessage = New MailMessage
eMail.To = "xxxxxxx"
eMail.BodyFormat = MailFormat.Html
eMail.From = "xxxxxxxx"
eMail.Subject = "intermedia mail test using 127.0.0.1"
eMail.Body = sMsg
SmtpMail.SmtpServer = "xxxxxxx 'AppSettings("MailServer")
SmtpMail.Send(eMail)
Thanks in advance
You are getting this error because the mail server is configured to only send mail from certain domains or the client is not in its list of accepted senders.
You need to get in touch with the mail server administrator and ask them to allow the IP address of the machine that the application resides on or send the mail using an address in the correct domain.
http://www.ietf.org/rfc/rfc1893.txt

configuring smtp in iis 7 for sending emails from classic asp application

I want to configure the smtp server on iis7. Its a website done on classic asp from which i am sending email. I get the error code as -2147220973.
I have configured the email address and stmtp server name in IIS 7
Is there anything else need to be configured ? or what is the error code means ?
CDOSYS Error: Error Number:
-2147220973 Error Source: CDO.Message.1 Error Description: The
transport failed to connect to the
server.
Looks like IIS is not able to connect to SMTP server, make sure you are using the correct SMTP server, some web hosts, such as GoDaddy require you to use their SMTP server to control spam issues. Check you web hosts support documentation. Also CDOSYS, the e-mail component used in ASP doesn't read the IIS configuration, as in IIS 7 that is used for ASP.NET and not ASP Classic. IIS 7 is configured by default to use localhost.
Take a look at the code below and make sure your code is using the correct SMTP server.
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail#mydomain.com"
myMail.To="someone#somedomain.com"
myMail.TextBody="This is a message."
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
myMail.Send
set myMail=nothing
%>
http://www.w3schools.com/asp/asp_send_email.asp
I have also written a simple ASP function that uses a Dictionary object to send e-mail with CDOSYS. That can make sending e-mail a little bit easier in ASP Classic.
http://www.simplecontactus.com

cdoSendUsingPort gives 8004020f but cdoSendUsingPickup works

I am using cdo to send email the following code fails
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "localhost"
.Update
End With
When I send an email I get the following error
8004020f
I then changed the code to the following:
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPickup
.Item(cdoSMTPServer) = "localhost"
.Update
End With
The email sends without a problem. What steps could I take to troubleshoot why cdoSendUsingPort is not working?
With cdoSendUsingPort, CDO tries to open a connection to the SMTP server you specify (in your case, localhost) on TCP port 25. I guess you're not running an SMTP server on your machine, so nothing is listening on port 25 and the call fails.
With cdoSendUsingPickup, CDO forwards the message to the pickup directory of your local IIS instance for later processing. I guess you have IIS installed on your machine and its SMTP module is configured to use pickup, so the call succeeds.
Professor Google finds (in order):
- Several options: server disallows anonymous relaying, server rejects specific recipient domains, recipient is rejected by SMTP server in unexpected way, and/or proxy or firewall settings are blocking the mail.
- Your mailserver is configured to not relay from your source machine.
- ... and several more things which boil down to the first link listed.
Some of these things you can test directly by telnet-ing from the sending machine to the mailserver, performing a normal SMTP interaction, and seeing what messages are displayed.

Resources