System.Net.Mail vs System.Web.Mail

G

Guest

I want to use the new System.Net.Mail instead of the old System.Web.Mail.

I'm getting an error "Hot not specified" when I try to do my last two lines:

System.Net.Mail.SmtpClient SMTP = new SmtpClient();
SMTP.Send(Message); //Error happens here


But the thing is, in my old use of System.Web.Mail, I never had this
problem. Why do I HAVE to specify the host in the new version and I didn't
have to in the old?

Alex
 
S

sharmil

Hi,

In oldversion when using System.web.Mail, the SmtpMail class automatically
uses the built-in mail service in Windows 2000. But in new version,
SmtpClient class does not use any default mail service. Hence when using
System.Net.Mail namespace, you need to specify the host.

SmtpClient mailObj = new SmtpClient();
mailObj.Host = "name of the host";

(or)

SmtpClient mailObj = new SmtpClient( "name of the host");
MailMessage mail = new MailMessage("(e-mail address removed)", "(e-mail address removed)",
"Testing", "Hello Everybody");
mailObj.Send(mail);

Regards,
Sharmila
 
W

Walter Wang [MSFT]

Thank you Sharmila for your input.

Hi Alex,

Thank you for your post.

Unlike System.Web.Mail, which was introduced in the 1.0 Framework,
System.Net.Mail is not built upon the CDO/CDOSYS libraries. Instead it is
written from the ground up without any interop. Thus, it is not dependant
upon on other COM libraries. Although some functionality has been removed,
the new System.Net.Mail namespace is much more versatile than the older CDO
dependant System.Web.Mail.

Other than Sharmila's input about specifying the server in code, you can
also config the Host, Credentials and Port properties for SmtpClient by
using the settings in the application or machine configuration files. For
example:

<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network
host="localhost"
port="25"
defaultCredentials="true"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top