Sending HTML Mail with ASP.NET 1.1

R

Ray Booysen

Hi all

I'm sending email via ASP.NET in HTML mode. Each email has exactly one
attachment and I do have full access to the SMTP server. However, if I
send the email in HTML format, the framework reports the following
exception:


"System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80040605): Unknown
Error\r\n --- End of inner exception stack trace ---\r\n at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)\r\n at
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, ParameterModifier[]
modifiers, CultureInfo culture, String[] namedParameters)\r\n at
System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
binder, Object target, Object[] args)\r\n at
System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj,
String propName, Object propValue)\r\n at
System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propValue)\r\n --- E
nd of inner exception stack trace ---\r\n at
System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propValue)\r\n at
System.Web.Mail.CdoSysHelper.Send(MailMessage message)\r\n at
System.Web.Mail.SmtpMail.Send(MailMessage message)\r\n at
XYZ.Utils.SendEmail(MailMessage Message, String SMTPServer) in
c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 406\r\n at
XYZ.Utils.SendEmail(String From, String To, String Bcc, String Cc,
String Subject, String Body, String[] Attachments, MailFormat Format,
String SMTPServer) in c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 392\r\n
at XYZ.Utils.SendEmail(String From, String To, String Bcc, String Cc,
String Subject, String Body, String[] Attachments, MailFormat Format) in
c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 396\r\n at
XYZ.Email.butSend_Click(Object sender, EventArgs e) in
c:\\inetpub\\wwwroot\\XYZ\\email.aspx.cs:line 178"

However, sending in plain text works perfectly.
Any ideas?

Regards
Ray
 
R

Ray Booysen

Hi Andrei

Here is the method:

public static void SendEmail(MailMessage Message, string SMTPServer) {
if (SMTPServer != "")
SmtpMail.SmtpServer = SMTPServer;
SmtpMail.Send(Message);
}

Which is called by an overloaded method:

public static void SendEmail(string From, string To, string Bcc, string
Cc, string Subject, string Body, string[] Attachments,
System.Web.Mail.MailFormat Format, string SMTPServer)
{
MailMessage _mm = new MailMessage();
_mm.From = From;
_mm.To = To;
_mm.Subject = Subject;
_mm.Body = Body;
_mm.BodyFormat = Format;
_mm.Cc = Cc;
_mm.Bcc = Bcc;

foreach (string s in Attachments)
_mm.Attachments.Add(new System.Web.Mail.MailAttachment(s));
SendEmail(_mm, SMTPServer);
}

Andrei said:
I'm not sure what you are doing wrong since you haven't shown us your source
code, but try following this tutorial in sending HTML emails with
attachements:

http://www.geekpedia.com/tutorial124_Sending-emails-with-ASP-.NET.html

Best regards,
Andrei

Ray Booysen said:
Hi all

I'm sending email via ASP.NET in HTML mode. Each email has exactly one
attachment and I do have full access to the SMTP server. However, if I
send the email in HTML format, the framework reports the following
exception:


"System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80040605): Unknown
Error\r\n --- End of inner exception stack trace ---\r\n at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture,
String[] namedParameters)\r\n at System.RuntimeType.InvokeMember(String
name, BindingFlags invokeAttr, Binder binder, Object target, Object[]
args, ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)\r\n at System.Type.InvokeMember(String name,
BindingFlags invokeAttr, Binder binder, Object target, Object[] args)\r\n
at System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj,
String propName, Object propValue)\r\n at
System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String propName,
Object propValue)\r\n --- E
nd of inner exception stack trace ---\r\n at
System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String propName,
Object propValue)\r\n at System.Web.Mail.CdoSysHelper.Send(MailMessage
message)\r\n at System.Web.Mail.SmtpMail.Send(MailMessage message)\r\n
at XYZ.Utils.SendEmail(MailMessage Message, String SMTPServer) in
c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 406\r\n at
XYZ.Utils.SendEmail(String From, String To, String Bcc, String Cc, String
Subject, String Body, String[] Attachments, MailFormat Format, String
SMTPServer) in c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 392\r\n at
XYZ.Utils.SendEmail(String From, String To, String Bcc, String Cc, String
Subject, String Body, String[] Attachments, MailFormat Format) in
c:\\inetpub\\wwwroot\\XYZ\\utils.cs:line 396\r\n at
XYZ.Email.butSend_Click(Object sender, EventArgs e) in
c:\\inetpub\\wwwroot\\XYZ\\email.aspx.cs:line 178"

However, sending in plain text works perfectly.
Any ideas?

Regards
Ray
 
R

Ray Booysen

Mark said:
You're not using McAfee VirusScan, are you...?
Nope, but I think I've got the issue, but not the solution. IIS is
running on my laptop for my dev environment. I was working from home
this weekend with the SMTP virtual server set to forward to the server
at the office. It seems the SMTP server doesn't like relaying over the
VPN for some reason as today it is working perfectly.

Regards
Ray
 
R

Ray Booysen

Ray said:
Nope, but I think I've got the issue, but not the solution. IIS is
running on my laptop for my dev environment. I was working from home
this weekend with the SMTP virtual server set to forward to the server
at the office. It seems the SMTP server doesn't like relaying over the
VPN for some reason as today it is working perfectly.

Regards
Ray
OK wait, I lie. Same issues occurring on another machine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top