[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1070
  • Last Modified:

How to make sending emails possible in IIS7?

Hello everyone,

I'm sure this is easy to find on the web, but I simply can't. All articles I found are related to IIS6.
So my question is how do send emails from IIS7, using ASP.
I prefer to use my provider's SMTP server. (mail.kpnplanet.nl)

Could any1 make or link a detailed guide for this? (IIS7!)
An ASP code coming with it is welcome.

Thanks, Aidiakapi
0
Aidiakapi
Asked:
Aidiakapi
1 Solution
 
strickddCommented:
If you are not using the local SMTP (as you describe) it is simply a matter of making sure that CDO or CDOSYS is installed on the server and that the server doesn't have port 25 block - firewall or antivirus can block port 25.

Are you getting an error when trying to send an e-mail? Please send any error you get.
0
 
AidiakapiAuthor Commented:
I get this error:
ADODB.Fields error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/vrijwilligersportaal/emailTest.asp, line 5

When trying this code in the codebox. (The emailadresses are cut down, they are private.)
I got this code from the internet, so what is wrong with it?
<%
	Set cdoConfig = CreateObject("CDO.Configuration")

	With cdoConfig.Fields
		.Item(cdoSendUsingMethod) = cdoSendUsingPort
		.Item(cdoSMTPServer) = "mail.kpnplanet.nl"
		.Update
	End With

	Set cdoMessage = CreateObject("CDO.Message")

	With cdoMessage
		Set .Configuration = cdoConfig
		.From = "z...d@z...g.nl"
		.To = "c...n@g...l.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>"
%>

Open in new window

0
 
hesCommented:
Change the cdoconfig to try this
Dim cdoConfig ' As CDO.Configuration
Dim Fields     ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set cdoConfig = Server.CreateObject("CDO.Configuration")
Set Fields = cdoConfig.Fields

       With Fields
 .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "mail.kpnplanet.nl"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "USERNAME" ' add this
      .Item(cdoSendPassword)          = "PASSWORD"  ' and this
      .Update
        End With
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tobzzzCommented:
I use the below code to send out my emails from IIS7 offline as I couldn't get a mailserver working. This is tried and tested way.

Save the below into test.asp, change the following:
1. mail.website.com
2. info@website.com
3. PasswordHere
Then the two email addresses in the last line. Then run the page and check your email :-)

/ Tobzzz
<% 
Sub sendmail(fromAddress,toAddress,subject,bodyText,bcc) 
        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 
         
        ' Get a handle on the config object and it's fields 
        Set objConfig = Server.CreateObject("CDO.Configuration") 
        Set Fields = objConfig.Fields 
         
        ' Set config fields we care about 
        With Fields 
                .Item(cdoSendUsingMethod)       = cdoSendUsingPort 
                .Item(cdoSMTPServer)            = "mail.website.com" 
                .Item(cdoSMTPServerPort)        = 25 
                .Item(cdoSMTPConnectionTimeout) = 10 
                .Item(cdoSMTPAuthenticate)      = cdoBasic 
                .Item(cdoSendUserName)          = "info@website.com" 
                .Item(cdoSendPassword)          = "passwordhere" 
                .Update 
        End With 
         
        Set objMessage = Server.CreateObject("CDO.Message") 
        Set objMessage.Configuration = objConfig 
         
        With objMessage 
                .To       = toAddress 
                .From     = fromAddress 
                .Subject  = subject 
                .HTMLBody = bodyText 
                .Send 
        End With 
         
        Set Fields = Nothing 
        Set objMessage = Nothing 
        Set objConfig = Nothing 
End Sub 
 
'Now send an email to test it works 
sendMail "sender@website.com","recipient@website.com","Email subject here","Main email content here.",null 
%>

Open in new window

0
 
AidiakapiAuthor Commented:
If I'd send mail from a domain, do I need the domain's SMTP. And should I use that username and password then. (The domain is: www.zwembaddebosberg.nl, it's a swimming pool with extremely advanced systems for a lot of things so, I'm making the website and want to try the mailfunctions on my own host.)
0
 
tobzzzCommented:
Use the code I've provided for offline testing on IIS7. I would imagine that your live server has mailserver setup correctly and you can use the below code for live sending.

/ Tobzzz
<%
sub sendmail(fromAddress,toAddress,subject,bodyText,bcc)
	Dim objMail
	    Set objMail = Server.CreateObject("CDO.Message")
	    objMail.To=toAddress
	    objMail.From=fromAddress
	    objMail.Subject=subject
	    objMail.HTMLBody=bodyText
	    if not bcc="" then objMail.Bcc=bcc
	    objMail.Send
	    Set objMail = Nothing
end sub

'Now send an email to test it works  
sendMail "sender@website.com","recipient@website.com","Email subject here","Main email content here.",null  
%>

Open in new window

0
 
AidiakapiAuthor Commented:
Tobzzz, thank you for the code. It seems an improvement, but it still doesn't work as it should.
I've put all data in correctly (I know it's correct, because I just created it and it works with webmail.), and I get the following error:

CDO.Message.1 error '80040213'
The transport failed to connect to the server.
/vrijwilligersportaal/emailTest.asp, line 41

Line 41 is the .send line, in the With clause.
0
 
AidiakapiAuthor Commented:
.Item(cdoSendUserName) =  "address" is the same address I send from, so that's not the problem
0
 
tobzzzCommented:
Did you changed all of these 3 lines:
.Item(cdoSMTPServer)            = "mail.website.com"  
.Item(cdoSendUserName)          = "info@website.com"  
.Item(cdoSendPassword)          = "passwordhere"  
and this line:
sendMail "sender@website.com","recipient@website.com","Email subject here","Main email content here.",null
?

/ Tobzzz
0
 
AidiakapiAuthor Commented:
As I said I changed it to correct values.
First line: SMTP server
Second line: The emailadres (which = equal to the username)
Third line: The password

About the last line, I changed the sender to the same emailadres as the username. And I changed the recipient. For testing I don't need to change the subject, I did add a HTML tag to the content.
My code now looks like:
<%
	Sub sendmail(fromAddress, toAddress, subject, bodyText, bbc)
		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

		' Get a handle on the config object and it's fields
		Set objConfig = Server.CreateObject("CDO.Configuration")
		Set Fields = objConfig.Fields

		' Set config fields we care about
		With Fields
			.Item(cdoSendUsingMethod)       = cdoSendUsingPort
			.Item(cdoSMTPServer)            = "mail.zwembaddebosberg.nl"
			.Item(cdoSMTPServerPort)        = 25
			.Item(cdoSMTPConnectionTimeout) = 10
			.Item(cdoSMTPAuthenticate)      = cdoBasic
			.Item(cdoSendUserName)          = "noreply@hidden.nl"
			.Item(cdoSendPassword)          = "passwordHidden"
			.Update
		End With

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

		With objMessage
			.To       = toAddress
			.From     = fromAddress
			.Subject  = subject
			.HTMLBody = bodyText
			.Send
		End With

		Set Fields = Nothing
		Set objMessage = Nothing
		Set objConfig = Nothing
	End Sub

	'Now send an email to test it works
	sendMail "noreply@hidden.nl", "hidden@gmail.com", "Email subject here", "Main email <b>content</b> here.", Null
%>

Open in new window

0
 
tobzzzCommented:
If you're using:
mail.zwembaddebosberg.nl
as your SMTP server, your:
.Item(cdoSendUserName)          = "XXX"
line must be using an email address from that domain like
.Item(cdoSendUserName)          = "SOMETHING@zwembaddebosberg.nl"

I just wanted to check, Is that what you're doing? If you are and it's still not working, do you know the IP address for your SMTP, It might be worth trying that instead.
0
 
AidiakapiAuthor Commented:
It's like that, I'm just not wanting the world to see it, cause of spam bots.
SMTP: mail.zwembaddebosberg.nl
USERNAME: noreply@zwembaddebosberg.nl

Believe me, they information in the code is correct.
0
 
tobzzzCommented:
Sorry, I have to rule one thing out at a time.

Can you try this:

1). Change:
.Item(cdoSendUsingMethod)       = cdoSendUsing
to:
.Item(cdoSendUsingMethod)       = 1

2). And then change:
.Item(cdoSMTPServer)            = "mail.zwembaddebosberg.nl"
to:
.Item(cdoSMTPServer)            = "http://127.0.0.1"

...and tell me what happens?

/ Tobzzz
0
 
AidiakapiAuthor Commented:
Whenever I change the first one from:
.Item(cdoSendUsingMethod)       = cdoSendUsingPort
To:
.Item(cdoSendUsingMethod)       = 1

I directly get this error:
CDO.Message.1 error '80040222'
The pickup directory path is required and was not specified.
/vrijwilligersportaal/emailTest.asp, line 41

When I change both it's still the same.

When I only change 2 I get the same error as before:
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
/vrijwilligersportaal/emailTest.asp, line 41

But then a lot faster, probably because of DNS lookup. (Without the HTTP:// it's also the same.)

Since the question's getting tougher I'm adapting the points, depending on how much more difficult (in slight bits).
0
 
tobzzzCommented:
You can also try
.Item(cdoSMTPServer) = "localhost"
but I don't think that will do it.

Can you use Telnet to see if you can connect OK:
Run Telnet, type: o mail.zwembaddebosberg.nl 25
It seems OK to me from here, I get:
220 w02.psp.uniserver.nl ESMTP MailEnable Service, Version: 0-4.17- ready at 04/
10/10 11:24:35

See what you get...

Do you have another domain and email address you could try, ideally on another hosting, just to eliminate the access details as the issue?
/ Tobzzz
0
 
AidiakapiAuthor Commented:
Well I know the emailaddresses work, because we have schedule application that send and reads mail (at the same domain).
I installed Telnet client and I get this error.

I can't connect:
Could not open connection to the host, on port 23.

So I turned of antivirus, and I portforwarded my router at ports 23 and 25 (which were both closed).
Still get the same error tough.

Also on the ASP page still the same error.
0
 
tobzzzCommented:
If you're not able to connect via telnet then the script is [probably] fine and it's port/server/iis settings which is a bit beyond my area of expertise. It's port 25 you should be using and that will need sorting. I guess the port is either being used elsewhere, is blocked for some reason or it's an antivirus/firewall type issue.
0
 
AidiakapiAuthor Commented:
So how to solve it?

Antivirus is turned of, ports are open at the router. About the Windows Firewall, I can't imagine it blocking it's own programs.

Anyone else?
0
 
tobzzzCommented:
This is the same problem: http://www.ureader.com/msg/152721.aspx
Re firewall they're saying:
"can she/he: telnet their.mailserver.com 25 from their workstation? if not, that would likely be firewall related"
... "Or the ISP blocks port 25."

From 15mins of Googling most issues seem to match yours where telnet proves they cannot connect on port 25. A fair few hits said anti-virus or Firewall were the issue.

I'm sorry I cannot help further, I would Google "unblocking port 25" as it seems to be the issue, not the code. In the meantime though, it's worth clicking request attention and mention the problem is now not code but server setup and you need attention from experts in that area, the mod will alert people in the correct zones with the appropriate knowledge.

Best of luck

/ Tobzzz
0
 
AidiakapiAuthor Commented:
I found the solution. It was that I should use my ISP's server.
Simply changing mail.zwembaddebosberg.nl to mail.kpnplanet.nl

Still thanks a lot for your help! The snippets work very well.
0
 
AidiakapiAuthor Commented:
Sorry for accidentally canceling. First question so.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now