Solved

Problems with sending email via CDO through a remote SMTP server

Posted on 2008-10-05
10
271 Views
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: http://bytes.com/forum/thread53504.html  However, since I can send through outlook, doesn't this rule that out?

From here: http://classicasp.aspfaq.com/email/why-does-cdo-message-give-me-8004020f-errors.html

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 = "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"

	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

		.Update

	End With

	Set objMessage = Server.CreateObject("CDO.Message")

	Set objMessage.Configuration = objConfig

	With objMessage

        .To = "support@myserversdomain.com"

        .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"

		.Send

	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

0
Comment
Question by:djlurch
  • 6
  • 4
10 Comments
 
LVL 1

Author Comment

by:djlurch
Comment Utility
Here is the error: error '8004020f' which occurs on the .Send line
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
Comment Utility
>>.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)

to:
Sub TestEmailSettings2(smtp_username,smtp_password,smpt_mail_server)

OR change:
.Item(cdoSMTPServer)            = smtp_mail_server

to:
.Item(cdoSMTPServer)            = mail_server
0
 
LVL 1

Author Comment

by:djlurch
Comment Utility
hielo:

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.
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>3) Unlikely
If you send from outlook, to tha "bad address" does it bounce?
0
 
LVL 1

Author Comment

by:djlurch
Comment Utility
Hielo:

Re-reading 3 I see that it talks about an invalid email address. The send to and from email addresses are both valid.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>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.
0
 
LVL 1

Author Comment

by:djlurch
Comment Utility
Hielo:

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?
0
 
LVL 1

Author Comment

by:djlurch
Comment Utility
Update:

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).
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>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.
0
 
LVL 1

Author Comment

by:djlurch
Comment Utility
How does the web host know that it is my server and not Outlook?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now