cdoSendUsingPort gives 8004020f but cdoSendUsingPickup works - asp-classic

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.

Related

CDOSYS error '80040213' - failed to connect to server

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.

Socket.Connect to SMTP to verify email always returns with smtp connection timeout

I've written a tool that validates emails, mostly copied from various examples on the subject around on the internet (user Don Worthley compiled a decent collection of code samples here https://delicious.com/dworthley/email.validation). Unfortunately after creating the socket and the IPEndPoint from the email to verify's hostname IP and port, my code always fails to connect to the socket due to timeout.
Here is the pertinent code (fails at s.Connect(endPt) due to timeout):
private bool smtpCheckEmail(string email)
{
try
{
string[] host = (email.Split('#'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
using (Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
try
{
s.Connect(endPt);
}
catch
{
s.Close();
return false;
}
From my research others have reported success with similar code so it might be an issue with my server host. The MVC project is on a GoDaddy VPS with Windows 7 and standard firewall/MSSE as protection (I've tested with both disabled with same timeout result).
I've verified I can telnet to my own host and run through the various HELO, Mail from etc commands but it also times out if I try to connect to smtp for other hosts.
Maybe it's an ISP issue?
I've also tried installing EmailVerify for .NET trial but run into the same problem where any validation at or above SMTP check times out.
Would be great to get some suggestions of what might be the problem and how to troubleshoot it.
Edit: After doing some comparison testing with one of my Azure VPS it looks like it is likely to be server related, "telnet 74.125.206.108 smtp" (gmail's smtp host IP) through command line connects on the Azure box but not on the GoDaddy one my project is on.
I also notice that when my code pulls the IP from the host name (Dns.GetHostEntry(hostname)), in this gmail example it returns 216.58.216.37 which matches what I get if a run nslookup in cmd for gmail.com, however the IP for smtp that I can telnet to is for gmail is 74.125.206.108 which matches the nslookup record for smtp.gmail.com. Could my code be grabbing the wrong IP addresses in many cases here?
Turned out to be a limitation of GoDaddy VPS. Transferred code to an Azure hosted project and it worked great.

retrieve mail info from an imap server

I want to retrieve some e-mail informations from a Imap mail server.
I'm using Railo application server (not coldfusion).
After defining attributes values (serverURL,login and pswd) , I used the following instruction to open a connection:
<cfimap server = "#serverURL#" username = "#login#" action="open" password = "#pswd#" port='993'>
Unfotunately, it generates the following error:
Connection timed out: connect;
nested exception is:
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
As it says, connection timed out. Make sure that the url and ports are correct and, if the imap server is self hosted, to open port 993 as in the example on the imap server.
Also be aware that depending on how you authenticate / connect changes the default port that is used with IMAP.
The default ports for IMAP are:
Standard Port:143
Secure IMAP (IMAP4-SSL) Port:585
IMAP4 over SSL (IMAPS) Port:993
A easy way to test the credentials is to first connect a desktop mail client like Thunderbird or Apple Mail first. Then use those settings on the CFML Server.
Also sometimes the username requires the domain so even if the username is "john" you may have to authenticate with "john#yourdomain.com".

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

Why do I have a slow initial response using by the Active Directory server?

Connecting to a named Active Directory server in the DMZ (i.e. not in the domain), over port 636 using DirectoryEntry then pulling attributes using DirectorySearcher.
String
string serverPath = "LDAP://some.domain.com:636/OU=XXXX,DC=xxxx,DC=xxxxxxxxx";
var searchRoot = new DirectoryEntry(
serverPath,
User,
Pass,
AuthenticationTypes.Secure);
The first query is very slow, around 22-25 seconds. It was explained to me that this may because IIS 7.5 may be doing a look up of the certificate on the AD server against a CRL, but not getting a response. Then, subsequent queries accept that answer until the process times out, so that the next query will again take 22-25 seconds.
Is the type of connection that I've described in my code example actually pull the certificate, or is the traffic simply sent over the port in an encrypted state, without a handshake between servers relative to the cert?
Is it mandatory that I IIS have a certificate as well for this to work? I should say that I am using this pattern: http://forums.asp.net/p/907421/1007517.aspx.
SSL isn't involved here.
What's serverPath look like? You probably are timing out on something - DNS perhaps. I'd start with a network trace.
When you use port 636, LDAP over SSL is used,
http://en.wikipedia.org/wiki/Ldap
If you use Microsoft Network Monitor or Wireshark to capture the packets, you may gain more insights on packet level.
In this case, CRL is necessary as it is enabled by default. But you can turn it off on machine or application level,
http://www.page-house.com/blog/2009/04/how-to-disable-crl-checking.html

Resources