By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Send mail using System.Web.Mail fails w/ m.BodyFormat=MailFormat.H

P: n/a
Hi,

I receive an access denied error (see below) when attempting to send an
email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same
code works fine in a console application, and also succeeds from the asp.net
page with BodyFormat=MailFormat.Text.

I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework
v1.1 SP1. The code worked fine under W2K SP4.

Any ideas? I've seen the same problem posted on the web a few times but
have not seen a response.

The error:
Server Error in '/WebMailTest' Application.
--------------------------------------------------------------------------------

Unknown Error
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Unknown Error

Source Error:
Line 28:
Line 29: SmtpMail.SmtpServer = "<name removed>";
Line 30: SmtpMail.Send(mm);
Line 31: }
Line 32:
Source File: c:\inetpub\wwwroot\webmailtest\webform1.aspx.cs Line: 30

Stack Trace:
[COMException (0x80040605): Unknown Error]

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture,
String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, ParameterModifier[] modifiers,
CultureInfo culture, String[] namedParameters) +473
System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
binder, Object target, Object[] args) +29
System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj,
String propName, Object propValue)
System.Web.Mail.LateBoundAccessHelper.SetProp(Obje ct obj, String
propName, Object propValue)

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundAccessHelper.SetProp(Obje ct obj, String
propName, Object propValue)
System.Web.Mail.CdoSysHelper.Send(MailMessage message)
System.Web.Mail.SmtpMail.Send(MailMessage message)
WebMailTest.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webmailtest\webform1.aspx.cs:30
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032

The code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace WebMailTest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mm = new MailMessage();
mm.To = "<valid e-mail address removed>";
mm.From = "<valid e-mail address removed>";
mm.Subject="test";
mm.BodyFormat = MailFormat.Html;
mm.Body = "<h1>hello</h1>";

SmtpMail.SmtpServer = "smtp.gb.rothschild.com";
SmtpMail.Send(mm);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

Feb 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thanks - that site was my first port of call when I experienced the problem
but to no avail (although someone did raise exactly the same question it
remains unanswered).

"Patrick.O.Ige" wrote:
Visit www.systemwebmail.com
You should get a solution there
patrick

"Ryan" <ap****@noemail.noemail> wrote in message
news:C2**********************************@microsof t.com...
Hi,

I receive an access denied error (see below) when attempting to send an
email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the
same
code works fine in a console application, and also succeeds from the
asp.net
page with BodyFormat=MailFormat.Text.

I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net
Framework
v1.1 SP1. The code worked fine under W2K SP4.

Any ideas? I've seen the same problem posted on the web a few times but
have not seen a response.

The error:
Server Error in '/WebMailTest' Application.
--------------------------------------------------------------------------------

Unknown Error
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Unknown
Error

Source Error:
Line 28:
Line 29: SmtpMail.SmtpServer = "<name removed>";
Line 30: SmtpMail.Send(mm);
Line 31: }
Line 32:
Source File: c:\inetpub\wwwroot\webmailtest\webform1.aspx.cs Line: 30

Stack Trace:
[COMException (0x80040605): Unknown Error]

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture,
String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, ParameterModifier[]
modifiers,
CultureInfo culture, String[] namedParameters) +473
System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
binder, Object target, Object[] args) +29
System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj,
String propName, Object propValue)
System.Web.Mail.LateBoundAccessHelper.SetProp(Obje ct obj, String
propName, Object propValue)

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundAccessHelper.SetProp(Obje ct obj, String
propName, Object propValue)
System.Web.Mail.CdoSysHelper.Send(MailMessage message)
System.Web.Mail.SmtpMail.Send(MailMessage message)
WebMailTest.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webmailtest\webform1.aspx.cs:30
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET
Version:1.1.4322.2032

The code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace WebMailTest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mm = new MailMessage();
mm.To = "<valid e-mail address removed>";
mm.From = "<valid e-mail address removed>";
mm.Subject="test";
mm.BodyFormat = MailFormat.Html;
mm.Body = "<h1>hello</h1>";

SmtpMail.SmtpServer = "smtp.gb.rothschild.com";
SmtpMail.Send(mm);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}


Feb 27 '06 #2

P: n/a
Hi Ryan,

I think this should be a environment specific issue. Are you encountering
the same problem on some other server? Also, are you sending the email
through exchange server or a custom smtp server and does that server
require authentication. In addition, since console application and ASP.NET
application are running under differernt process identity and logon
session, I think you can also try make your ASP.NET page use windows
authenticaion and impersonate the client user to see whether this can make
the application work. If work, the problem should be related to the
executing security identity.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Feb 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.