Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use CDO to send email?

Status
Not open for further replies.

snakehips2000

Programmer
Nov 10, 2003
95
0
0
GB
As an ASP newbie, I've looked at other threads and applied code to create a simple ASP page for users to send me email from a web page as follows:

<%
Set objMessage = Server.CreateObject("CDO.Message")
With objMessage
.To = "me@myaddress.com" //replace with valid address
.From = "him@hisaddress.com" //replace with valid address

.Subject = "Message Subject"
.TextBody = "Message Body"
.Send
End With
Response.write("Done")
Set objMessage = Nothing
%>

If I preview the page in IE, the message "Done" appears. I assume, therefore, that there are no syntax errors. However, the email does not arrive.

I'm confused. I'm running Windows 2000, IIS5, and normally use Outlook Express to view/send emails within Hotmail. I have installed the SMTP service. Do I have to configure the SMTP service in some way for this code to work?

I also see in some threads that I need to specify a "mail server" name. Where would I find this?

I don't want to get needlessly bogged down by this but my head's in a spin at the moment so any guidance is appreciated.
 
Does anything end up in the Inetpub\Mailroot\Badmail folder?
 
Hi Sheco and DotNetGnat, thanks for the responses.

I see that there are several files in the Badmail folder, with either a BDR or BAD file extension. Also while looking in that Inetpub\Mailroot folder I looked in the "Queue" folder. Judging by the timestamps, all my attempts to send this one simple email are there!

Where does that leave me?

Presumably there's something very basic that's gone over my head.
 
You might want to examine some of those files with a text editor like Notepad just to make sure they contain the proper To/From address, etc.

Assuming the files are correct, the IIS Virtual SMTP Server is probably failing to hand the mail off to a real SMTP server. Are you developing for a company's intranet or a public internet site?
 
since all the emails are in the queue folder, that means your server is not picking up them and relaying them to the mail folder...so in the mail settings you will find something called "Relay"...make sure those settings are correctly set...

-DNG
 
Sheco - all the files in the Queue folder are correctly addressed (i.e. To, From etc). The site is for a public internet site.

DotNetGnat - I followed your instructions re "Relay". When I right-click "Default SMTP Virtual Server" in IIS, then click "Properties", "Access", "Relay", the checkbox "Allow all computers which successfully authenticate to relay, regardless of the list above" is checked.

Additionally, I have the following: in Properties", "Access", "Authentication". The selected authentication methods are "Anonymous Access", "Basic Authentication", and "Windows Security Package".

As I'm still testing the website, I view all my results via "localhost" on my Testing Server. However, as an experiment, I FTP'd the ASP page and the calling web page to my remote (Microsoft hosting) server and tried running it from there - still no email.

 
I seem to remember having a similar problem and it was something to do with not having outgoing mail set up correctly. I had to put the name of our ISP's outgoing mail server in 'Smart Host' (IIS, SMTP server properties, Delivery, Advanced)

I'm short of time at the moment but I may be able to dig out the original thread tomorrow.
 
OK, so from the replies I've seen, the issue seems to lie with how my IIS SMTP server is set up. However, I'm still baffled by it all - in particular about what value I have to put into the "Smart Host" box.

So that someone can put this into simple language for me: the ISP I use to access the internet in the UK is BTBroadband. If I go to a DOS prompt and type in "nslookup" I get the following returned:

Default Server: indnsc61.ukcore.bt.net
Address: 194.72.0.114

The website I'm creating will be hosted by In their setup documentation, they list their "incoming mail server" as "imap.1and1.co.uk", and their "outgoing mail server" as "auth.smtp.1and1.co.uk"

If, at the DOS prompt I type in:

> nslookup imap.1and1.co.uk
I get ...
Server: imap.1and1.co.uk
Addresses: 212.227.15.154, 212.227.15.138

*** imap.1and1.co.uk can't find nslookup: No response from server

... and then type ...
>nslookup auth.smtp.1and1.co.uk
I get ...
Server: auth.smtp.1and1.co.uk
Addresses: 212.227.15.179, 212.227.15.163

*** auth.smtp.1and1.co.uk can't find nslookup: No response from server

Could someone please tell me what is relevant, what isn't, and which values in the SMTP properties boxes I need to amend to configure this SMTP service.
 
in the Smart Host text box...you need to enter your mail server address...something like...

mail.mycorp.com or ip address...

-DNG
 
Assuming you are testing on your local box with a view to implementing on a web server at some point, the Smart Host setting should match the outgoing mail server you have used in Outlook or Outlook Express I guess. As far as I remember, I just set up that one property.

My original thread, for what it's worth was thread333-1016535 which, in turn refers to a further thread.
 
I think I'm at the stage where I tear my hair out. I'm now not even sure what this whole SMTP thing is meant to do. Let's look at the bigger picture. I have a remote (Microsoft hosted) website on which I have successfully setup a mail account in such a way that when a user sends a normal email to the site's email address from their own email application, I receive a copy of that email in my Hotmail Inbox (which I view via Outlook Express). I know that this works perfectly because I have sent an email to the address and I received a copy of that email a few seconds later.

To try and configure SMTP I opened Outlook Express, Tools, Accounts, selected Hotmail, Properties, Server. In the "Server URL", I copied " and pasted it into the SMTP, Properties, Delivery, Advanced, "Smart Host" box. I then get a message "Domain Name is not valid".

Perhaps someone could email me (brianmcb@hotmail.com) some screen shots of all these SMTP properties boxes so that I can see where I could be getting bogged-down by all of this?

As I'm trying to test my email script locally. Am I right in presuming that this is the only reason for having to configure the SMTP server?

My ultimate aim is to enable a user to send an email programmatically from a page on the site. To do this I have an ASP script(see the first post in this thread for the code) which seems to run without error when I preview it locally in a browser as it returns "Done". I've placed this ASP file on the web server ensuring it is placed in the correct directory from which it is being called. However, when the user clicks the Submit button on the page, nothing happens - no copy email is received by me and, hence, the beginning of this thread.
 
I think you may be looking in the wrong place in Outlook Express. You need to select the 'Mail' tab and find the account you use for outgoing mail then click on properties, Servers tab, Outgoing mail (SMTP).
 
That's the same place I was looking isn't it? I selected Hotmail from the list of accounts in the "All" tab (which is also listed identically in the "Mail" tab).

Also, after selecting Hotmail, the "Server" tab states that Hotmail is an HTTP server (no "Outgoing Mail" option). That's why I used the "Server URL" value mentioned in the previous post.
 
OK but looks like you are getting slightly different dialog. I'm not sure if Hotmail works differently to ther providers. Do you have any other mail accounts you could use?

I use Outlook for outgoing mail but when I tried setting up an account in Outlook Express (using wizard) and subsequently select that account, the properties dialog has a Servers tab with an outgoing mail server (SMTP). I think all you need to do is find a valid outgoing server and plump it in that Smart Host box.

I have a feeling BT Broadband does not provide an outgoing mail server but that may be worth investigating?
 
Snake,

Unless the mail server is setup to receive or route mail from an smtp server then most likley it will never work. Your local computer (smtp) is not set up to to communicate with hotmail's server.

This is done to to stop spam.............



Programming today is a race between software Developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots.....So far Universe 1 Developers 0
 
ctdapper, I reckon there's a lot of truth in that. I've abandoned all hope of going down the hotmail route but, as you can probably gather from all the previous posts in this thread, I can't get the ASP script to send an email even after uploading it to the web server - even though all seems well syntax-wise within the script.
 
Do you know whether Web Server is IIS? I know that, when we did a site under Sun One ASP, we had to switch from CDO to CDONTS. So we now use the 'switchable' code below. You could try it - just declare MailType at module level and set to "CDONTS" or "CDO". The ISP advised us to set server to 'localhost'.

Code:
'**********************************************************
'* Send an email - using whatever technology available -  *
'* e.g. CDO, CDONTS etc.                                  *
'**********************************************************
Function LfnSendMail(WhoFrom, WhoTo, Subject, Msg, WhoBcc, Fmt)
  Dim objMail
  If MailType="CDO" Then 
    Set objMail = Server.CreateObject("CDO.Message") 
  Else
    Set objMail = Server.CreateObject("CDONTS.NewMail") 
  End If
  If WhoFrom="" Then WhoFrom="webmaster@wherever.co.uk"
  If WhoTo=""   Then WhoTo=EmailTo
  If WhoTo=""   Then WhoTo="myemail@mydomain.co.uk"
  With objMail 
    .To=WhoTo
    .From = WhoFrom
    .Subject = Subject
    If MailType="CDO" Then 
      .TextBody = Msg
    Else
'     .Host = "specificsmtpserver.co.uk"
      .Host = "localhost"
      .BodyFormat=Fmt   '0=HTML, 1=Text
      If WhoBcc<>"" Then .Bcc=WhoBcc
      .Body = Msg
    End If
    .Send 
  End With
  set objMail = nothing
 End Function
 
Glasgow, yes, I tried using some code very similar to your suggestion a couple of days ago. Script ran from beginning to end returning an "OK" response message for both CDO and CDONTS yet no email received.
 
How frustrating. Believe me I know how you feel. My best suggestion would be to try your code locally either on another machine that sends mail via a non-hotmail SMTP server or 'borrow' connection details for such a server from someone else, test within Outlook Express then try your code, specifying the server in Smart Host.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top