System.Web.Mail.MailMessage.From property assignment problem

P

Phil Mc

Hi has anyone come accross the problem....
with referance to System.Web.Mail.MailMessage and
System.Web.Mail.SmtpMail

THIS WORKS FINE
mail=new MailMessage();
mail.From = "W-MyPcName.mycompany.com";
mail.To=strTo;
mail.Cc=strCC;
mail.Bcc=strBCC;
mail.Subject = strSubject;
mail.Body = strBody;


THIS DOES NOT WORK ????
string machine = Environment.MachineName + ".mycompany.com";
mail=new MailMessage();
mail.From = machine ;
mail.To=strTo;
mail.Cc=strCC;
mail.Bcc=strBCC;
mail.Subject = strSubject;
mail.Body = strBody;

When you look at the the value in 'mail.From' on both of the above, the

EXACT same string is present.
Its got me, any help welcome :)

The error message is as follows:
Error source: System.Web
Message: Could not access 'CDO.Message' object.
Stack: at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
obj, String
methodName, Object[] args)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at PCOMClassLibrary.SendMailMessage.SendMail() in
c:\dotnetwork\pcomclasslibr
ary\sendmailmessage.cs:line 101
 
N

Nicholas Paldino [.NET/C# MVP]

Phil,

This happens when you assign the value to the field, or when you try and
send? My guess is that the values are not actually the same.

The error you are showing indicates that you are having a problem when
sending the mail (not setting the value), and that it can't access the CDO
object. This leads me to believe that you do not have CDO or CDONT
installed on the machine you are trying to send mail from.

Quite honestly, I wouldn't recommend the mail classes in the
System.Web.Mail namespace (because of the CDO and SMTP requirements). If
you are using .NET 2.0, use the classes in the System.Net.Mail namespace or
if you are using .NET 1.1, use the classes in the Indy Project
(http://www.indyproject.org).

Hope this helps.
 
P

Phil Mc

Thanks for that Nicholas;
Unfortunately I am stuck with .NET 1.1 at present and cannot use the
third party classes you suggested. The frustrating this about this is
that when I inspect the two versions and get their respective hash
codes that are the same:
string machine = Environment.MachineName.ToString() +
".prudential.com".Trim();
int a1 = machine.GetHashCode();
int a2 = "W-I557425F.prudential.com".GetHashCode();
Looks like Ill have to go back and reinvent the wheel, and write my own
smpt class.

Thanks for your help.
 
N

Nicholas Paldino [.NET/C# MVP]

Why can't you use the indy project libraries?

Also, you didn't address the other items I mentioned, about CDO and
SMTP, since the error you received was not from setting the property, but
from sending the message.
 

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

Top