November 7, 2005

System.Net.Mail

Seems to me that Microsoft has deprecated the System.Web.Mail, & replaced it with the System.Net.Mail. When I try to send an email using the System.Web.Mail it gives the message obsolete with a warning. Below is the code sample for sending simple SMTP emails with .NET 2.0.

public void SendEmail()
    {
        //.Net 1.0 System.Web.Mail -- Is now Depre
        /*
       //We can use the constructor as well; e.g.
       /*MailMessage mail = new MailMessage("ludmal@test.com", "ludmal@tst.lk", "Test", "test");*/

        MailMessage mail = new MailMessage();
        mail.To = "ludmal@e-solutions.lk";
        mail.From = "ludmal@test.com";

        mail.Body = "Body Testing";
        SmtpMail.SmtpServer = "mail";
        SmtpMail.Send(mail);
        */

        //.Net 2.0 System.Net.Mail
        MailMessage mail = new MailMessage("ludmal@test.com", "ludmal@tst.lk", "Test", "test");

        /*MailAddressCollection col = new MailAddressCollection();
        MailAddress sendAdd = new MailAddress("ludmal@e-solutions.lk");
        */

        System.Net.Mail.SmtpClient client = new SmtpClient("mysmtp");
        client.Send(mail);
    }

1 comment:

Anonymous said...

Tks!
Worket with me!
I was using the system.web.mail and I was send for multiple users..