/egilh

Learning by doing

Error using SmtpMail: Could not access 'CDO.Message' object

Posted on Friday, December 09, 2005 5:46 PM

I recently got a problem sending e-mail using System.Web.Mail.SmtpMail while implementing a system for notifying users that their password is about to expire. The SMTP server I was using supports authentication and .NET 1.1 automatically tries to log in if the server supports it. This is an edited network trace of the request that failed:

220 somehost Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready
EHLO egilh
250-somehost Hello [10.0.4.44]
...
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
<250 OK AUTH LOGIN
<334 ...
>...=
<334 ...
>...==
<535 5.7.3 Authentication unsuccessful.

There is no properties for disabling automatic authentication, but you can control the behavior of the SMTP client using the Fields collection. The line in bold below shows how to control the authentication

System.Web.Mail.SmtpMail.SmtpServer = "10.10.*.*";
 
System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
message.From = "from@***.com";
message.Subject = "Mail subject";
message.To = "to@***.com";
message.Body = "And this is the body of the message";
 
// Set NO authentication (0=>none, 1=>basic, 2=>integrated)
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 0);
 
System.Web.Mail.SmtpMail.Send(message);
 

The http://schemas.microsoft.com/cdo/configuration namespace allows you to control a lot of other features as well. The most useful ones:

  • sendusername: User name to authenticate with
  • sendpassword: Password to authenticate with
  • smtpconnectiontimeout: Set the connection time out
  • smtpserverport: Control which port is used
  • smtpusessl: Use SSL when sending mail



Feel free to drop a few cents in the tip jar if this post saved you time and money

Feedback

# re: Error using SmtpMail: Could not access 'CDO.Message' object

2/19/2007 8:33 AM by mohit

this is only test.


Post Comment
Title
 

Name
 

Url

Protected by Clearscreen.SharpHIPEnter the code you see:
Comment