Problems with sending email via CDO through a remote SMTP server

Posted on 2008-10-05
Last Modified: 2009-09-30
I am using CDO / ASP to send email via a remote server.

In 4 out of 5 accounts it is working. Each account is using a separate mail server and username/password.

The problem account has the correct username, password, and mail server settting. I know this because using Outlook I am able to send an receive messages.

Is there a setting on the mail server of the problem account that may be preventing the proper sending of the emails?

One suggested answer was that the server isn't allowing emails to be relayed from my server:  However, since I can send through outlook, doesn't this rule that out?

From here:

1) I don't think the SMTP server requires authentication since I can send it via Outlook without it
2) A possible error
3) Unlikely
4) Unknown
5) Didn't resolve the issue

Sub TestEmailSettings2(smtp_username,smtp_password,mail_server)
 	On Error Resume Next
	Const cdoSendUsingMethod = ""
	Const cdoSendUsingPort = 2
	Const cdoSMTPServer = ""
	Const cdoSMTPServerPort = ""
	Const cdoSMTPConnectionTimeout = ""
	Const cdoSMTPAuthenticate = ""
	Const cdoBasic = 1
	Const cdoSendUserName = ""
	Const cdoSendPassword = ""
	Dim objConfig  ' As CDO.Configuration
	Dim objMessage ' As CDO.Message
	Dim Fields     ' As ADODB.Fields
	Set objConfig = Server.CreateObject("CDO.Configuration")
	Set Fields = objConfig.Fields
	With Fields
		.Item(cdoSendUsingMethod)       = cdoSendUsingPort
		.Item(cdoSMTPServer)            = smtp_mail_server
		.Item(cdoSMTPServerPort)        = 25
		.Item(cdoSMTPConnectionTimeout) = 10
		.Item(cdoSMTPAuthenticate)      = cdoBasic
		.Item(cdoSendUserName)          = smtp_username
		.Item(cdoSendPassword)          = smtp_password
	End With
	Set objMessage = Server.CreateObject("CDO.Message")
	Set objMessage.Configuration = objConfig
	With objMessage
        .To = ""
        .From = smtp_username & "<" & smtp_username & ">"
        .Subject = "Test Message: " & smtp_username
        .TextBody = "This is a test message to see if your email settings were configured properly"
	End With
	Set Fields = Nothing
	Set objMessage = Nothing
	Set objConfig = Nothing
 	If Err.Number <> 0 Then
 		Call ClearSMTPEmailSettings(djidnumber)
 		Call DisplayError("We were able to connect to the mail server. However, there appears to be a setting on your server that is preventing the proper relaying of messages. Please recheck the settings and try again or leave the settings blank.")
 	End If
End Sub

Open in new window

Question by:djlurch
  • 6
  • 4

Author Comment

ID: 22646735
Here is the error: error '8004020f' which occurs on the .Send line
LVL 82

Accepted Solution

hielo earned 500 total points
ID: 22646755
>>.Item(cdoSMTPServer)            = smtp_mail_server
the name of the variable in the function argument is just mail_server NOT smtp_mail_server. So, either change:
Sub TestEmailSettings2(smtp_username,smtp_password,mail_server)

Sub TestEmailSettings2(smtp_username,smtp_password,smpt_mail_server)

OR change:
.Item(cdoSMTPServer)            = smtp_mail_server

.Item(cdoSMTPServer)            = mail_server

Author Comment

ID: 22646768

Excellent catch. I never saw that. Does not resolve the issue. The calling Sub in the main page properly populated the variable on a global scope. The code is fully functional for 4 out of 5 tested accounts.  It is just one account that is causing problems.

Please note that I don't have access to the mail server for the account, only the user/pass/mail location.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

LVL 82

Expert Comment

ID: 22646837
>>3) Unlikely
If you send from outlook, to tha "bad address" does it bounce?

Author Comment

ID: 22646851

Re-reading 3 I see that it talks about an invalid email address. The send to and from email addresses are both valid.
LVL 82

Expert Comment

ID: 22646929
>>The send to and from email addresses are both valid.
It's not limited to invalid addresses. The remote inbox may be full OR it may not be accepting emails from the specified email address perhaps because it has been "black listed" as a spammer. The point of 3 is that your script is not telling you the "REAL" reason for the rejection. That's why I am asking if it bounces when you send via outlook. Perhaps you have more details there.

Author Comment

ID: 22744253

No, it doesn't bounce.

I read somewhere about email accounts requiring a POP retrieval before allowing a message to be sent. Any way to check if this is the case?

Author Comment

ID: 22940138

I got an email from the mail administrator. The said "we do not allow relaying". I'm not sure I see the difference between Outlook Pop and send and the ASP CDOSYS/CDONTS component (on the backend).
LVL 82

Expert Comment

ID: 23454816
>>I'm not sure I see the difference between Outlook Pop and send and the ASP CDOSYS/CDONTS component (on the backend).
If Outlook is installed in Joe's PC, then Joe is responsible for all email originating from that account and/or pc(it's traceable). On an ASP script, anybody could use your web page to generate (spam) email but chances are YOU are not the one that would be held responsible for the actual content of said spam.

Author Comment

ID: 23482648
How does the web host know that it is my server and not Outlook?

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question