Sending Email via Exchange server and System.Web.Mail

  • Thread starter Thread starter RedEye
  • Start date Start date
R

RedEye

Hello,

I am trying to create a class to send email via POP3 or Exchange.

Everything works fine when sending via POP3 but fails when sending via
exchange.
Error: Could not access 'CDO.Message' object.

The following code works fine in a VB.Net test app but fails on the web.
Does anyone have an idea why??

'--------------------------------------------------------------------
Dim mMail As New mail.MailMessage
Dim smtp as mail.SmtpMail

With mMail
.From = _addressFrom
.To = _sendTo
.Cc = _CC
.Subject = _subject
.Body = _body
.BodyFormat = _format
End With

' Check if the server type is POP3 or MS Exchange
If _mailServerType = ServerType.POP3 Then
smtp.SmtpServer = _smtpHost
Else
' The following code is need to authenticate to a exchange server
' Where the 2 specifies NTLM, 1 for basic, 0 for none (the default)
Dim userid As String = String.Format("{0}\{1}", _domain, _mailbox)

mMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthent
icate", 2)

mMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusernam
e", userid)

mMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpasswor
d", _password)

mMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver"
, _smtpHost)
End If

smtp.Send(mMail)
'--------------------------------------------------------------------

Thanks,
RedEye
 
Hi,

The most common cause is security issue. The default ASP.NWT user
doesn’t have permissions to access CDO objects. You can check if its
security two ways:
1) Remove anonymous access and add Identity tag with impersonate
attribute to web.config.

2) Use Identity tag with user and password attribute set to user with
sufficient rights.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Thanks for the input but it didn't work.

1) I tried what you suggested - no go.
2) I gave power user rights to ASPNET user - no go.

I will keep trying other things.

Thanks again!!
 
Back
Top