Classic ASP, Sending E-mail on windows server 2008 - error '8004020f' - iis-7

I am trying to send e-mail with classic ASP (I am stuck with an old app so I have to use classic ASP here) on Windows Server 2008 R2, IIS 7.5.
I guess lots of thing change from win server 2003 to 2008. I am using the following code but I am getting this error (BTW, error message is so "informative");
error '8004020f'
/poo.asp, line 32
Here is the code;
<!--
METADATA
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->
<%
'Declare variables
Dim sch, cdoConfig, cdoMessage
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail.example.com"
'Set SMTP port which is 25 by default
.Item(sch & "smtpserverport") = 587
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "info#example.com"
.To = "me#example2.com"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO.message"
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Response.write "<HTML><head><title>A message has been sent.</title></head><body>A message has been sent.</body></HTML>"
%>
Also, I just installed Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=1004 into my server but it didn't change anything.
NOTE: I could send e-mail over localhost if it works. doesn't matter.

You might come across the following error:
error '8004020f' The event class for this subscription is in an
invalid partition
This error message comes from cdosys.h, and has nothing to do with any sort of "partition" - it is actually lumped in with other errors in an overloaded message. The error code is actually attributed to the following:
CONST LONG CDO_E_RECIPIENTS_REJECTED = 0x8004020FL
Which means that the e-mail was rejected by the server for some reason. Here are some things you can try to alleviate the problem:
Make sure the SMTP server allows anonymous (non-authenticated) relaying. If your SMTP requires outgoing authentication, see Article #2026.
Check if the problem is specific to the domain name(s) used in the e-mail addresses of the recipients. For example, some users have complained that they can send to users on their own domain only; others have said that they can send to any domain except their own (see Article #2511 for some potential causes and solutions).
It may be simply that the e-mail address is being rejected, but other configuration settings on the SMTP server are preventing the true error message from being relayed propely back to the ASP script ... so verify that the address is valid.
If you have a proxy or firewall, make sure the web server is set up to correctly pass through it, that the SMTP server knows about it, and that the proxy allows access to port 25.
Try using a SendUsing value of 1 (pickup) instead of 2 (port). E.g. the following line:
.Item(cdoSendUsingMethod) = cdoSendUsingPort
Becomes
.Item(cdoSendUsingMethod) = cdoSendUsingPickup
http://classicasp.aspfaq.com/email/why-does-cdo-message-give-me-8004020f-errors.html

Related

Error sending an email with VB.NET using gmail smtp

I have a small website, there is a contact form that uses the gmail's smtp to send an email.
here's the code:
Dim MyMailMessage As New System.Net.Mail.MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("office#mydomain.com")
MyMailMessage.To.Add("test#mydomain.com")
MyMailMessage.Subject = "MSG"
MyMailMessage.IsBodyHtml = True
MyMailMessage.Body = "TEXT"
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("user", "pass")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
Return True
Catch exx As SmtpException
Throw exx
End Try
The error i am getting is :
5.5.4 HELO/EHLO argument invalid, closing connection. ks5sm2862700wjb.13 - gsmtp
Google just started blocking any connection which attempts a HELO/EHLO with incorrect arguments. According to RFC 5321, there should be one argument to EHLO/HELO, and it should be the name of the machine sending the mail.
The most common broken config is not sending any argument, which is what you're doing. The error message isn't that great in that you'd have to notice the two spaces that have your "empty" argument in the middle.
For regular mail sending, giving a hostname that matches the IP address you're sending from (ie, the DNS PTR lookup) is the most correct name to use.
For smtp-msa (ie, user/password based submission to smtp.gmail.com), that's less important, but it should still be the fully qualified domain name of the server, if it's available.
Google isn't enforcing the full requirements of RFC 5321 for this field, yet, but if you're going to fix it, it's best to do so correctly.
I don't see anything on the SmtpClient object to set what to send, so it's either completely broken, or it is making some internal call to get the hostname which is returning an empty string.
I was having the same problem, starting this morning.
We were setting the sender's email address as the argument for EHLO, and it was balking at that. I believe the # was causing the problem. This must be a new requirement, because this worked for years.
I changed the EHLO command to "EHLO google" and it works again.

Why emails are getting stuck in pick-up folder when sending through SMTP Service and CDO?

I'm programming Classic Asp with IIS8.5, so for sending email I use the SMTP Service (not the SMTP Server) with the CDO component. I want to send email using the pickup directory option:
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
So my code is:
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-relay.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxx#gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "The-pwd-123"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") ="C:\inetpub\correos\"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.BodyPart.Charset = "unicode-1-1-utf-8"
.To = "YYY <yyy#gmail.com>"
.From = "XXX <xxx#gmail.com>"
.Subject = "This is a subject"
.TextBody = "This is the body of the message"
.Send
End With
As you may know IIS8.5 come without SMTP Server, so there is no folder for the pickup directory (or I haven't found it yet), you must created, the problem I'm having is that the emails are getting stuck into the folder I created for that purpose.
https://support.google.com/a/answer/176600?hl=es
When you use the cdoSendUsingPickup option, you are simply writing the email message to a file which will be queued up for delivery asyncronously from your code. Yes, this is dramatically faster as your code does not have to wait for the SMTP server to receive the message. So, when using this option, you do not need to specify the destination SMTP server, the port, the username, password, etc.
Hopefully you are now asking yourself how does the server know where to send the message to if I don't specify a forwarding SMTP server. Well, that's because you just have to configure the Microsoft SMTP Service to let it know what server to hand off the messages to. There are plenty of articles online to configure it so you should not have any trouble finding that.

IIS 7 + Windows Server 2008 - Sending Emails from Classic ASP using CDO

On our existing platform we decided to upgrade our development server from Windows Server 2003 to 2008 some time ago.
The problem we are facing is that all asp scripts that used to send emails before when we had Windows Server 2003 worked. Now, they stopped working with no error on page or on the SMTP logs.
If I use telnet to send an email manually works fine.
But it's not working from our classic asp scripts.
This is our ASP code
Sub SendEmail(fromEmail, toEmail, ccEmail, bccEmail, subject, body, somefiles)
Set m_Mailer = Server.CreateObject("CDO.Message")
With m_Mailer.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smptserver") = Request.ServerVariables("server_name")
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")=SMTP_SERVER_PICKUP_DIRECTORY
.Update
End With
If m_CharacterSet <> "" Then
m_Mailer.BodyPart.Charset = m_CharacterSet
End If
m_Mailer.To = toEmail
m_Mailer.CC = ccEmail
m_Mailer.BCC = bccEmail
m_Mailer.From = fromEmail
m_Mailer.ReplyTo = fromEmail
m_Mailer.Subject = subject
If m_UseHtmlFormat Then
m_Mailer.HTMLBody = FixText(body)
Else
m_Mailer.TextBody = FixText(body)
End If
Dim i
somefiles = Split(somefiles, vbTab)
For i = 0 to UBound(somefiles)
m_Mailer.AddAttachment(somefiles(i))
Next
m_Mailer.Send
End Sub
I've checked permissions on the mailroot folder and the IIS user has full control. I've already set the relay to 127.0.0.1, and gave the IIS User access to the smtp as well.
When I use telnet I get everything on the log and receive the email correctly.
But even when using this test script I don't get any email, they stay stuck on the pickup folder
Dim emailer
Set emailer = New EmailHelper
emailer.SendEmail "test#test.com", "fede#shocklogic.com", "", "", "Test 1 2 3 from " & Request.ServerVariables("HTTP_HOST"), "Test...", ""
Set emailer = Nothing
Response.Write "DONE"
When I try to execute this test script I always get "DONE" on the page, but no email.
SMTP is already installed and enabled.
Any help would be great
Found the solution! (At least it works for me)
I removed this line
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")=SMTP_SERVER_PICKUP_DIRECTORY
And configured SMTP in IIS 7 console to use localhost instead of pickup directory and works perfect now!

CDOSYS : how to check if it's working?

On a client server, we have a little script that send an email at the end of an order, just before closing it.
Until yesterday everything works fine, but suddenly, the page gives a generic 500 error.
so I start from the bottom of the page find that if I put a response.end just before the .send of the cdo mail function, the page works fine:
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "mail.theserver.com"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPAuthenticate) = cdoAnonymous '0
Flds.Update
With iMsg
Set .Configuration = iConf
.To = "mymail#mail.com"
.From = "amail#mail.gov"
.Sender = ""
.Subject = "test"
.HTMLBody = "TEST"
RESPONSE.END()
.Send
End With
On the page there are also two lines at the beginning:
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
Well, I’ve already done some test putting some script to send emails a little different from this one but nothing seems to work. Does anybody know a way to test the cdosys? Something that. I don't know, return the version... or a list of options... well, something that makes me know that the error is on the server (and so I could phone to them and tell "hey it's not my fault")...?
Edit:
Since the page gives only a 500 error, is there a way to makes the server returns a more specific error code? i can't access the server, but only the ftp (so only classic asp)
Edit 2: i have add this code:
on error resume next
.Send
If Err.Number <> 0 Then
Response.write(Err.Number)
response.write("<br>")
response.write(Err.description)
end if
and it gives this message:
-2147220975
Impossibile inviare il messaggio al server SMTP. Codice errore di trasporto: 0x800ccc6f. Risposta del server: 554 Your access to this mail system has been rejected due to the sending MTA's poor reputation.
Based on your error message the CDO component is working but your SMTP sever (MTA) is rejecting the message. Maybe because of the .gov domain? Regardless you have a poor SMTP reputation for spamming. You need to use a different SMTP server. If you are using the ip of the IIS server, than that IP is no longer good, and has been blacklisted by spam servers.
Mailchimp has a lot of information on mail deliverable. Take a look at it.
You can use a hosted SMTP service (mailgun, sendgrid, mandrill), all of which will block you right away if you are spamming.

Classic ASP - Sending Email To Own Domain with CDOSYS fails

I have a classic asp email script that uses authenticated CDOSYS to send to emails from a database. It's running on a Parallels Plesk Windows 2008 server.
This works fine for all email addresses except for any addresses that belong to sites on the server I am sending from.
I could authenticate using a Google Apps email account (the domain is set up using Google Apps for email) BUT I would run up against Google' 24 hour sending limits each time the client ran the script.
Can anyone point out where I'm going wrong or explain why email to sites on the sending server causes an error? The error is
error '8004020f'
/admin/send-group-email.asp, line 128
which is the objCDO.Send line
The Code :
(primarydomain.com is the domain name of the primary account the site lives under in Parallels. The SenderEmail value would be, for example, id#secondarydomain.com)
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "localhost"
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUsername) = "authenticate#primarydomain.com"
.Item(cdoSendPassword) = "thepassword"
.Update
End With
while (NOT RS_Emails.EOF)
Dim objCDO
set objCDO = Server.CreateObject("CDO.Message")
objCDO.Configuration = cdoConfig
objCDO.From = CStr(Request.Form("SenderEmail")) & " (" & CStr(Request.Form("SenderName")) & ")"
objCDO.To = RS_Emails.Fields.Item("email").Value
objCDO.Subject = CStr(Request.Form("Subject"))
objCDO.HTMLBody = message
objCDO.Send
set objCDO = Nothing
RS_Emails.MoveNext
Wend
set cdoConfig=Nothing
This is most likely a server issues which can be solved with Plesk.
Please look at the following link:
http://mkb-training.com/index.php?option=com_content&view=article&id=1:setting-up-google-apps-with-plesk&catid=1:google-tutorial&Itemid=2
Pay attention to the following:
"Uncheck the MX1: "Domain IP also used for mail server"" (there are screenshots there on how to do this). I am not 100% sure about Plesk, but in H-Sphere (another Parallels control panel) doing this is essential for being able to send from the server to your own domain when you have a remote mail exchanger.
Also make sure that no MX records point to your server (even if the Google Apps ones are configured correctly).

Resources